How to enforce invariants using the type system

Hello helpful internet person!

My new job has introduced me to Go and I'd like some advice on domain modelling. I'd like to create a type that enforces a particular constraint and have the type be the proof of validity. This type would be used company wide and throughout our system.

For example, creating a subset of the string type with constraints on it's length.A naive approach:

var ErrStringTooLong = errors.New("too long")

type Max8String string

func NewMax8String(s string) (Max8String, error) {
	lengthOfString := len(s)
	if lengthOfString > 8 {
		return "", ErrStringTooLong
	}
	return Max8String(s), nil
}

func main() {
	var foo Max8String
	foo = "Length more than 8"
}

This obviously allows the constraint enforcement to be bypassed as it relies on convention. I understand exposing an interface to an underlying type but what would an "idiomatic" design of this interface look like?

It may be helpful to know that the true goal is to avoid sanity checks/validation logic throughout the code base AND to not rely on convention if possible.

πŸ‘︎ 5
πŸ“°︎ r/golang
πŸ’¬︎
πŸ‘€︎ u/AlmostNihilist94
πŸ“…︎ May 09
🚨︎ report
Mass is INVARIANT!!!
πŸ‘︎ 69
πŸ“°︎ r/physicsmemes
πŸ’¬︎
πŸ‘€︎ u/HoloandMaiFan
πŸ“…︎ Apr 30
🚨︎ report
Polynomials invariant under matrix transformation.

I recently saw an olympiad problem asking to characterize all polynomials P satisfying P(x,y)=P(x+2y,x+y). I tried to generalize this: given a square matrix A, find all polynomials P satisfying P(x)=P(Ax) for all vectors x. This is not too hard to do for diagonalizable matrices, but I couldn't do the general case. Are there any sources on such a topic?

πŸ‘︎ 94
πŸ“°︎ r/math
πŸ’¬︎
πŸ‘€︎ u/SupercaliTheGamer
πŸ“…︎ Apr 17
🚨︎ report
Fixed effect vs Random effect with time invariant variables

Hi guys,

So im working on my thesis, im doing a binary data panel regression.

I did the Hausman test to see if I should use fixed effects or random effects for a logit regression. The test is telling me that the correct one to use is the fixed effects, however when I run the model, i get this result:

2136 groups (6408 obs = 3/4 of the individuals) dropped because of all positive or all negative outcomes and also 3 important variables are omitted because they have no within-group variance, the sex of the individual and the fathers and mothers education.

My question is if this problem is enough reason to ignore the Hausman test, change the model and run one with random effects or maybe there is some other test that i could do, im a bit clueless on how to proceed now.

Also notice that with the random effects all my variables are significant, under fixed effects only one of my variables is significant.

Thank you in advanced

πŸ‘︎ 4
πŸ“°︎ r/econometrics
πŸ’¬︎
πŸ‘€︎ u/Matiuv9
πŸ“…︎ May 25
🚨︎ report
Mass is INVARIANT!!!
πŸ‘︎ 30
πŸ’¬︎
πŸ‘€︎ u/HoloandMaiFan
πŸ“…︎ Apr 30
🚨︎ report
LIFE: Lighting Invariant Flow Estimation - Augmented Reality Demo (NVIDIA) v.redd.it/1po6zdkws3t61
πŸ‘︎ 77
πŸ“°︎ r/computervision
πŸ’¬︎
πŸ‘€︎ u/AR_MR_XR
πŸ“…︎ Apr 14
🚨︎ report
[2102.11600] ASAM: Adaptive Sharpness-Aware Minimization for Scale-Invariant Learning of Deep Neural Networks arxiv.org/abs/2102.11600
πŸ‘︎ 12
πŸ“°︎ r/MachineLearning
πŸ’¬︎
πŸ‘€︎ u/evanatyourservice
πŸ“…︎ Apr 12
🚨︎ report
LIFE: Lighting Invariant Flow Estimation - Augmented Reality Demo (NVIDIA) v.redd.it/1po6zdkws3t61
πŸ‘︎ 83
πŸ“°︎ r/AR_MR_XR
πŸ’¬︎
πŸ‘€︎ u/AR_MR_XR
πŸ“…︎ Apr 14
🚨︎ report
Aggregate Design: Using Invariants as a Guide youtube.com/watch?v=64ngP…
πŸ‘︎ 64
πŸ“°︎ r/dotnet
πŸ’¬︎
πŸ‘€︎ u/codeopinion
πŸ“…︎ Apr 14
🚨︎ report
LIFE: Lighting Invariant Flow Estimation - Augmented Reality Demo (NVIDIA) v.redd.it/1po6zdkws3t61
πŸ‘︎ 60
πŸ“°︎ r/augmentedreality
πŸ’¬︎
πŸ‘€︎ u/AR_MR_XR
πŸ“…︎ Apr 20
🚨︎ report
Knot Invariants in Minecraft youtu.be/GEZSM8KnFD0
πŸ‘︎ 14
πŸ“°︎ r/CasualMath
πŸ’¬︎
πŸ“…︎ May 11
🚨︎ report
LIFE: Lighting Invariant Flow Estimation (NVIDIA) v.redd.it/1po6zdkws3t61
πŸ‘︎ 123
πŸ“°︎ r/nvidia
πŸ’¬︎
πŸ‘€︎ u/AR_MR_XR
πŸ“…︎ Apr 14
🚨︎ report
How to make CNN more scale invariant?

Let's say I want to classify some digits or letters but on images they have varying scale, some of them take up a whole image, others are much smaller.

What can I do to make my model more scale invariant in this case? Cropping seems like a good start but I wouldn't want to crop an image that has a very large symbol in it, because for example cropping out from image of 7 could make it look like 1 if I get rid of the top part.

Another idea is to preprocess data, but I cannot do it as the test set will also contain various scales. And more importantly I don't want to do it, if there's a technique that doesn't rely on preprocessing I'd like to learn about it just to learn something new.

What can I use here? I've heard and briefly read about stuff like pyramids, would this apply here? Or do you have any other ideas I could try out?

πŸ‘︎ 3
πŸ’¬︎
πŸ‘€︎ u/Gabe_The_Human
πŸ“…︎ Apr 30
🚨︎ report
Why exactly are wavefunctions "invariant" under a change of phase? Is it because elements of the space of square integrable functions from ℝ³ to β„‚ that differ by a phase are identical? That is, the same element in LΒ²(ℝ³)?
πŸ‘︎ 4
πŸ“°︎ r/AskPhysics
πŸ’¬︎
πŸ‘€︎ u/SK209920
πŸ“…︎ Mar 28
🚨︎ report
I’m supposed to find m st y=mx is invariant under the transformation below. I’m confused as to why not all real values of m work. How does the mark scheme conclude that ONLY +/-1 work? am I missing something?
πŸ‘︎ 25
πŸ“°︎ r/askmath
πŸ’¬︎
πŸ“…︎ Mar 26
🚨︎ report
"An EPIC (Equivalent-Policy Invariant Comparison) way to evaluate reward functions", Gleave et al 2021 (offline comparison of reward functions) bair.berkeley.edu/blog/20…
πŸ‘︎ 6
πŸ“°︎ r/ControlProblem
πŸ’¬︎
πŸ‘€︎ u/gwern
πŸ“…︎ Apr 29
🚨︎ report
Rotation invariant CNN embeddings

For the purpose of my university project, I want to achieve the following result.

Given 2 images where one in a rotated version of the other. I want output feature vectors to be as close as possible.

For this purpose, I am maximizing cosine similarity between them, but from the first iteration, it gives an output close to 1.

Do you have any suggestions on how can I solve this problem?

πŸ‘︎ 14
πŸ“°︎ r/computervision
πŸ’¬︎
πŸ‘€︎ u/IntInstance
πŸ“…︎ Mar 01
🚨︎ report
Characterization of Time-variant and Time-invariant Assessment of Suicidality on Reddit using C-SSRS [preprint] arxiv.org/pdf/2104.04140.…
πŸ‘︎ 2
πŸ“°︎ r/AcademicReddit
πŸ’¬︎
πŸ‘€︎ u/MFA_Nay
πŸ“…︎ Apr 16
🚨︎ report
Error Invariant Failed

Any idea why I can't connect my Binance Chain Wallet to Pancakeswap? Or what 'Error Invariant Failed' means?

https://preview.redd.it/cae7msb2qzm61.png?width=1920&format=png&auto=webp&s=6347d140f056d8f403bba6440340095681ac0d79

πŸ‘︎ 2
πŸ“°︎ r/pancakeswap
πŸ’¬︎
πŸ‘€︎ u/simonkohtao
πŸ“…︎ Mar 14
🚨︎ report
Knot Invariants in Minecraft youtu.be/GEZSM8KnFD0
πŸ‘︎ 3
πŸ“°︎ r/3Blue1Brown
πŸ’¬︎
πŸ“…︎ May 12
🚨︎ report
Loop invariants and Structural Induction

I've been thinking a lot of loop invariants and how they relate to structural induction. Sounds like they're 2 sides of the same coin.

Would it be fair to say any proof for an iterative algorithm I can make using a loop invariant, I should be able to make for the same algorithm expressed recursively using structural induction?

Also, would one method be preferred over the other when proving a property about a set or other recursively defined structure? As an example, let's say something like the merge algorithm in merge sort. I can see using both loop invariants and structural induction to prove its correctness depending on how I express the problem.

πŸ‘︎ 5
πŸ“°︎ r/algorithms
πŸ’¬︎
πŸ‘€︎ u/RazerWolf
πŸ“…︎ Mar 21
🚨︎ report
Data-Driven Inference of Representation Invariants: a subject that could become relevant to AGI youtube.com/watch?v=sOkDE…
πŸ‘︎ 6
πŸ“°︎ r/agi
πŸ’¬︎
πŸ‘€︎ u/pentin0
πŸ“…︎ Apr 02
🚨︎ report
[2102.11600] ASAM: Adaptive Sharpness-Aware Minimization for Scale-Invariant Learning of Deep Neural Networks arxiv.org/abs/2102.11600
πŸ‘︎ 2
πŸ“°︎ r/deeplearning
πŸ’¬︎
πŸ‘€︎ u/evanatyourservice
πŸ“…︎ Apr 12
🚨︎ report
"An EPIC (Equivalent-Policy Invariant Comparison) way to evaluate reward functions", Gleave et al 2021 (offline comparison of reward functions) bair.berkeley.edu/blog/20…
πŸ‘︎ 8
πŸ’¬︎
πŸ‘€︎ u/gwern
πŸ“…︎ Apr 29
🚨︎ report
You'll enjoy this series called Strangers, where an "invariant" is drawn to Earth to fight a creature, and then becomes the glue that holds together a team of extraterrestrial beings globalcomix.com/c/strange…
πŸ‘︎ 25
πŸ“°︎ r/SciFiScroll
πŸ’¬︎
πŸ‘€︎ u/nimloth
πŸ“…︎ Mar 16
🚨︎ report
Aggregate Design: Using Invariants as a Guide youtube.com/watch?v=64ngP…
πŸ‘︎ 2
πŸ“°︎ r/CodeOpinion
πŸ’¬︎
πŸ‘€︎ u/codeopinion
πŸ“…︎ Apr 14
🚨︎ report
This looks like the equation for Energy-momentum relation. it relates energy to invariant mass, which is the portion of mass of an object/system that is independent of the overall system. I think this was foreshadowing of Vison's growing autonomy from Wandas control. Just a thought.
πŸ‘︎ 15
πŸ“°︎ r/WANDAVISION
πŸ’¬︎
πŸ‘€︎ u/SynthesizedSquawk
πŸ“…︎ Feb 05
🚨︎ report
I’m supposed to find m st y=mx is invariant under the transformation. I’m confused as to why not all real values of m work. How does the mark scheme conclude that ONLY +/-1 work? Am I missing something?
πŸ‘︎ 7
πŸ“°︎ r/6thForm
πŸ’¬︎
πŸ“…︎ Mar 26
🚨︎ report
Zero To Production In Rust, Part Six: Using Types To Guarantee Domain Invariants lpalmieri.com/posts/2020-…
πŸ‘︎ 166
πŸ“°︎ r/rust
πŸ’¬︎
πŸ‘€︎ u/LukeMathWalker
πŸ“…︎ Dec 11 2020
🚨︎ report

Please note that this site uses cookies to personalise content and adverts, to provide social media features, and to analyse web traffic. Click here for more information.