More Features #1

Open
mattdesl opened this Issue Jun 29, 2015 · 14 comments

Comments

Projects
None yet
9 participants
@mattdesl
Collaborator

mattdesl commented Jun 29, 2015

The guide is not complete. More planned features:

  • cross product
  • tensor product
  • delta
  • dot product
    • common patterns like clamped dot product with angled brackets too specific I think
  • indefinite integral
  • ƒ - function
  • Heaviside function (step()) possibly too specific; already have sgn
  • common patterns like greek letters vs latin ?

And generally:

  • converting some complex/intimidating expressions into code
  • notation-to-code examples from real papers (e.g. graphics programming papers)

@mattdesl mattdesl changed the title from Notations to More Features Jun 29, 2015

@cihadturhan

This comment has been minimized.

Show comment
Hide comment
@cihadturhan

cihadturhan Jun 30, 2015

I didn't want to open a new issue. Instead, I'm adding here:

function clamp(a,b,c){
  return Math.max(b,Math.min(c,a));
}

function smoothstep(edge0, edge1, x)
{
    // Scale, bias and saturate x to 0..1 range
    x = clamp((x - edge0)/(edge1 - edge0), 0.0, 1.0); 
    // Evaluate polynomial
    return x*x*(3 - 2*x);
}
  • Angle conversions e.g. degree to radian
// Converts from degrees to radians.
Math.radians = function(degrees) {
  return degrees * Math.PI / 180;
};

// Converts from radians to degrees.
Math.degrees = function(radians) {
  return radians * 180 / Math.PI;
};
  • Spherical to cartesian etc
function sph2cart(vect) {
            //r, theta, phi
            var z = vect.x * Math.sin(vect.z);
            var rcoselev = vect.x * Math.cos(vect.z);
            var x = rcoselev * Math.cos(vect.y);
            var y = rcoselev * Math.sin(vect.y);
            return new THREE.Vector3(x, y, z);
        }
    };

I didn't want to open a new issue. Instead, I'm adding here:

function clamp(a,b,c){
  return Math.max(b,Math.min(c,a));
}

function smoothstep(edge0, edge1, x)
{
    // Scale, bias and saturate x to 0..1 range
    x = clamp((x - edge0)/(edge1 - edge0), 0.0, 1.0); 
    // Evaluate polynomial
    return x*x*(3 - 2*x);
}
  • Angle conversions e.g. degree to radian
// Converts from degrees to radians.
Math.radians = function(degrees) {
  return degrees * Math.PI / 180;
};

// Converts from radians to degrees.
Math.degrees = function(radians) {
  return radians * 180 / Math.PI;
};
  • Spherical to cartesian etc
function sph2cart(vect) {
            //r, theta, phi
            var z = vect.x * Math.sin(vect.z);
            var rcoselev = vect.x * Math.cos(vect.z);
            var x = rcoselev * Math.cos(vect.y);
            var y = rcoselev * Math.sin(vect.y);
            return new THREE.Vector3(x, y, z);
        }
    };
@JavDevGames

This comment has been minimized.

Show comment
Hide comment
@JavDevGames

JavDevGames Jun 30, 2015

+1 for indefinite integrals

I'd also vote for the laplace operator

Inspiring guide so far!

+1 for indefinite integrals

I'd also vote for the laplace operator

Inspiring guide so far!

@avdi

This comment has been minimized.

Show comment
Hide comment
@avdi

avdi Jun 30, 2015

This is a super cool project.

Something that baffled me when first reading FP literature was the frequent use of "prime" notation: e.g. an equation that contained both a and a' and sometimes even a''. It took me a while just to figure out what this was called.

Also, in general I have trouble grokking something if I can't "read it aloud" in my head. So any guidance for how to say notation is greatly helpful for people like me.

avdi commented Jun 30, 2015

This is a super cool project.

Something that baffled me when first reading FP literature was the frequent use of "prime" notation: e.g. an equation that contained both a and a' and sometimes even a''. It took me a while just to figure out what this was called.

Also, in general I have trouble grokking something if I can't "read it aloud" in my head. So any guidance for how to say notation is greatly helpful for people like me.

@mattdesl

This comment has been minimized.

Show comment
Hide comment
@mattdesl

mattdesl Jun 30, 2015

Collaborator

@cihadturhan cheers, I will consider those. I eventually hope to have another part of the repo that holds "practical examples" (aimed at graphics programming), and it might include turning equations into, say, GLSL built-ins like sign, step and smoothstep.

@avdi thanks for the feedback. See #5 which includes prime 😄

Collaborator

mattdesl commented Jun 30, 2015

@cihadturhan cheers, I will consider those. I eventually hope to have another part of the repo that holds "practical examples" (aimed at graphics programming), and it might include turning equations into, say, GLSL built-ins like sign, step and smoothstep.

@avdi thanks for the feedback. See #5 which includes prime 😄

@JavDevGames

This comment has been minimized.

Show comment
Hide comment
@JavDevGames

JavDevGames Jun 30, 2015

Dunno if this might interest you, but I found this website the other day: http://visualgo.net/ and the way they present their explanations is makes it seem really simple to understand (though they could use a bit less pseudocode IMHO)

Dunno if this might interest you, but I found this website the other day: http://visualgo.net/ and the way they present their explanations is makes it seem really simple to understand (though they could use a bit less pseudocode IMHO)

@tiborsaas

This comment has been minimized.

Show comment
Hide comment
@daemonna

This comment has been minimized.

Show comment
Hide comment
@daemonna

daemonna Jul 1, 2015

i would like to see matrix algebra features like transpose, complex conjugate, etc.. as matrices are real big deal :) and don't forget there are also other algebras than Gibbs (Clifford, etc)...

daemonna commented Jul 1, 2015

i would like to see matrix algebra features like transpose, complex conjugate, etc.. as matrices are real big deal :) and don't forget there are also other algebras than Gibbs (Clifford, etc)...

@richdutton

This comment has been minimized.

Show comment
Hide comment
@richdutton

richdutton Jul 2, 2015

this is excellent - thanks!

i think it would be really helpful to see example (simple) implementations of the functions mentioned, such as dot, cross and determinant

this is excellent - thanks!

i think it would be really helpful to see example (simple) implementations of the functions mentioned, such as dot, cross and determinant

@chmaruni

This comment has been minimized.

Show comment
Hide comment
@chmaruni

chmaruni Jul 2, 2015

I like the project a lot. I especially like the idea of focusing on mathematical operators (which are easy to write but can be pretty involved to compute) and not whole algorithms because there are plenty of books describing algorithms. I always think of mathematical operators as small programs and if I don't have a corresponding program in my head I don't really understand the operator. Having had a guide like yours would have saved me a ton of time when I was younger.

I would love to see a "numerical math" section which presents operators such as integrals, derivatives, gradients and laplacians etc. because using numerics is how most of these things are implemented in practice (and it's often easier to understand I think)

As examples: given are the values of a function f(x) at discrete points in the form of an array.

  • The derivative f'(p) at grid point p is just the difference of its neighbors f'(p) = f(p+1)-f(p).
  • A laplacian is somewhat similar the average of all the differences between the surrounding points in n dimensions.
  • An integral is just the sum of the values which shows the similarity in the used signs: a large cursive S for integral sums and a large Greek Sigma for the summation operator.

chmaruni commented Jul 2, 2015

I like the project a lot. I especially like the idea of focusing on mathematical operators (which are easy to write but can be pretty involved to compute) and not whole algorithms because there are plenty of books describing algorithms. I always think of mathematical operators as small programs and if I don't have a corresponding program in my head I don't really understand the operator. Having had a guide like yours would have saved me a ton of time when I was younger.

I would love to see a "numerical math" section which presents operators such as integrals, derivatives, gradients and laplacians etc. because using numerics is how most of these things are implemented in practice (and it's often easier to understand I think)

As examples: given are the values of a function f(x) at discrete points in the form of an array.

  • The derivative f'(p) at grid point p is just the difference of its neighbors f'(p) = f(p+1)-f(p).
  • A laplacian is somewhat similar the average of all the differences between the surrounding points in n dimensions.
  • An integral is just the sum of the values which shows the similarity in the used signs: a large cursive S for integral sums and a large Greek Sigma for the summation operator.
@mattdesl

This comment has been minimized.

Show comment
Hide comment
@mattdesl

mattdesl Jul 3, 2015

Collaborator

@chmaruni Thanks for the feedback. Things with limits (derivatives, integrals, infinity) are going to be tough to translate into code. Discrete points might work for certain things... The same is done here and makes sense to me. 😄

Collaborator

mattdesl commented Jul 3, 2015

@chmaruni Thanks for the feedback. Things with limits (derivatives, integrals, infinity) are going to be tough to translate into code. Discrete points might work for certain things... The same is done here and makes sense to me. 😄

@chmaruni

This comment has been minimized.

Show comment
Hide comment
@chmaruni

chmaruni Jul 3, 2015

I agree, operators with limits, infinites and infinitesimals sometimes seem borderline magic and hard to grasp. That's why I think that seeing how they operate on discrete functions (aka arrays) is so helpful, because more often than not they are pretty trivial things with fancy names.

chmaruni commented Jul 3, 2015

I agree, operators with limits, infinites and infinitesimals sometimes seem borderline magic and hard to grasp. That's why I think that seeing how they operate on discrete functions (aka arrays) is so helpful, because more often than not they are pretty trivial things with fancy names.

@chmaruni

This comment has been minimized.

Show comment
Hide comment
@chmaruni

chmaruni Jul 3, 2015

@mattdesl interesting video. He is still solving the integral analytically however (ie using transformation rules to get rid of the integrals) which is not exactly what I meant but still interesting of course. If you have the values of the function on an evenly spaced grid you can for example usd the trapezoidal rule, see "numerical implementation" here: https://en.m.wikipedia.org/wiki/Trapezoidal_rule

chmaruni commented Jul 3, 2015

@mattdesl interesting video. He is still solving the integral analytically however (ie using transformation rules to get rid of the integrals) which is not exactly what I meant but still interesting of course. If you have the values of the function on an evenly spaced grid you can for example usd the trapezoidal rule, see "numerical implementation" here: https://en.m.wikipedia.org/wiki/Trapezoidal_rule

@ghost

This comment has been minimized.

Show comment
Hide comment
@ghost

ghost Jul 4, 2015

I would love to see a "numerical math" section which presents operators such as integrals, derivatives, gradients and laplacians etc.

I would love too.

Things with limits (derivatives, integrals, infinity) are going to be tough to translate into code.

Exactly because they're tough to translate it's necessary to show even a few examples to give people idea how they can understand it.

I agree, operators with limits, infinites and infinitesimals sometimes seem borderline magic and hard to grasp. That's why I think that seeing how they operate on discrete functions (aka arrays) is so helpful, because more often than not they are pretty trivial things with fancy names.

Totally agree!

ghost commented Jul 4, 2015

I would love to see a "numerical math" section which presents operators such as integrals, derivatives, gradients and laplacians etc.

I would love too.

Things with limits (derivatives, integrals, infinity) are going to be tough to translate into code.

Exactly because they're tough to translate it's necessary to show even a few examples to give people idea how they can understand it.

I agree, operators with limits, infinites and infinitesimals sometimes seem borderline magic and hard to grasp. That's why I think that seeing how they operate on discrete functions (aka arrays) is so helpful, because more often than not they are pretty trivial things with fancy names.

Totally agree!

@Sphinxs

This comment has been minimized.

Show comment
Hide comment
@Sphinxs

Sphinxs Jan 18, 2018

Can be cool if you create a branch with mathematical formulas that we use in Machine Learn ( Gini, entropy, gain, similarity, euclidian distance ... ) ^ - ^

Sphinxs commented Jan 18, 2018

Can be cool if you create a branch with mathematical formulas that we use in Machine Learn ( Gini, entropy, gain, similarity, euclidian distance ... ) ^ - ^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment