3 ms·
The problem with numerical programming is that all data is the same type. If you access wrong row, multiply across wrong axis, function uses wrong parameters,
by nabla9 8y ago
The problem with numerical programming is that all data is the same type. If you access wrong row, multiply across wrong axis, function uses wrong parameters, it's semantically wrong, but it can still work and system can learn something.
- amelius 8y agoIsn't there a typesystem that can help with this? E.g., give rows a type, give columns a type, and then if you multiply two matrices, see if the type of the columns of the first matrix and the type of the rows of the second matrix match. Also, the typesystem could use units, just as they are used in physics.
- nabla9 8y agoYou would like to have 'unit system' that would keep track of the units of measure in general and the ability to use concepts like dimensional homogeneity to avoid semantic errors while programming. Alas, they don't exist as far as I know.
- anonymou2 8y agohttps://pint.readthedocs.io/en/0.9/ https://pint.readthedocs.io/en/0.9/
- alkonaut 8y agoF# has units of measure. A frontend is (usually) not F#, but even for a more loosely typed system such as your typical web frontend, it should be possible to represent scalars as tuples of a number and an identifier. Eg. { qty: 12, unit: "kgs" }.
- carlmr 8y agoF# has this: https://fsharpforfunandprofit.com/posts/units-of-measure/ https://fsharpforfunandprofit.com/posts/units-of-measure/
- AKrumbach 8y agoA search on Google turns up this Common Lisp code, which appears to define a number of SI units (both base and derived) in the sort of manner described. http://www-ksl.stanford.edu/knowledge-sharing/lib/unit-conversion-agent/standard-units-and-dimensions.lisp http://www-ksl.stanford.edu/knowledge-sharing/lib/unit-conve... Given the way this appears to be defining some sort of class-based hierarchy, with the correct type requirements this code should perform exactly the sort of unit/type checking the grandparent post wanted, but I didn't go digging into the rest of the project files to confirm this code defined things in the correct manner for that to work.
- alehander42 8y agoNim also has it
- chpatrick 8y agoWe use this at our startup. We have a Haskell math library where every vector/matrix/rotation knows the spaces they deal with (World, Camera, etc), and using them with incorrect spaces is a type error. This is enormously useful because in 3D computer vision/graphics almost everything is 3 or 4-dimensional, so it's very easy to use them the wrong way. When you read C++ computer vision code a datatype often has a Matrix3 or worse yet a double[] in it and you have no idea what coordinate system (or even matrix order) it represents. With this, it's all self-documenting and difficult to get wrong.
- em500 8y agoIn pandas you could/should use dataframe index and column labels that way, it automatically aligns by column and index names before arithmetic, unlike raw numpy arrays which aligns by position. It takes more discipline and some performance hit though. You could even do it with SQL field (column) names and natural joins. The performance hit is even bigger and discipline/retraining is even bigger, as few SQL users are used to thinking about column names (rather than types) as type definitions. Further, this would only catch a class of bugs that are relatively easy to spot manually. The difficult case is when the processes that generated the numbers have slowly changed in time (e.g., you have a very different mix of visitors/customers now than during model training).
- dual_basis 8y agoThere is a namedtensor library that tries to fix this.