Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement erf #59

Merged
merged 4 commits into from
Dec 12, 2023
Merged

implement erf #59

merged 4 commits into from
Dec 12, 2023

Conversation

mei1127
Copy link
Contributor

@mei1127 mei1127 commented Nov 29, 2023

Copy link
Contributor

@BruceDai BruceDai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @mei1127.

src/unary.js Outdated

export const erf = (input) => {
/**
*reference 1:https://en.wikipedia.org/wiki/Error_function
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, thanks.

Here we refer to an "Approximation with elementary function" with maximum error: 1.5×10−7 of Error function in Wikipedia as below figure:

image

and erf function of WebGL backend for TensorFlow.js.

const ERF = `
  // Error function is calculated approximately with elementary function.
  // See "Handbook of Mathematical Functions with Formulas,
  // Graphs, and Mathematical Tables", Abramowitz and Stegun.
  float p = ${backend_util.ERF_P};
  float a1 = ${backend_util.ERF_A1};
  float a2 = ${backend_util.ERF_A2};
  float a3 = ${backend_util.ERF_A3};
  float a4 = ${backend_util.ERF_A4};
  float a5 = ${backend_util.ERF_A5};

  float sign = sign(x);
  x = abs(x);
  float t = 1.0 / (1.0 + p * x);
  return sign * (1.0 - (((((a5*t + a4)*t) + a3)*t + a2)*t + a1)*t*exp(-x*x));
`;

src/unary.js Outdated Show resolved Hide resolved
@mei1127
Copy link
Contributor Author

mei1127 commented Nov 29, 2023

updated erf function in unary.js. PTAL, thanks!

Copy link
Contributor

@huningxin huningxin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, thanks!

Copy link

@fdwr fdwr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

src/unary.js Outdated
@@ -8,6 +8,8 @@ import {Tensor} from './lib/tensor.js';
* @param {Function} unaryFunc
* @return {Tensor}
*/


Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] Is it normal to insert 2 blank lines or 1?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I have deleted these two blank lines

@huningxin huningxin merged commit c4304f8 into webmachinelearning:main Dec 12, 2023
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants