-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { relu } from './relu'; // Import your relu function from your implementation file | ||
|
||
describe('relu', () => { | ||
it('should apply ReLU activation correctly for positive input', () => { | ||
// Define input and expected output for positive input | ||
const input = 3; // Positive input | ||
const expectedOutput = 3; // Expected output (same as input) | ||
|
||
// Convert input to a Field (assuming you have a way to represent numbers as Fields) | ||
const inputField = ...; // Convert input to a Field | ||
|
||
// Call the relu function | ||
const result = relu(inputField); | ||
|
||
// Assert that the result matches the expected output | ||
expect(result.toNumber()).toEqual(expectedOutput); | ||
}); | ||
|
||
it('should apply ReLU activation correctly for negative input', () => { | ||
// Define input and expected output for negative input | ||
const input = -2; // Negative input | ||
const expectedOutput = 0; // Expected output (ReLU turns negative input to zero) | ||
|
||
// Convert input to a Field (assuming you have a way to represent numbers as Fields) | ||
const inputField = ...; // Convert input to a Field | ||
|
||
// Call the relu function | ||
const result = relu(inputField); | ||
|
||
// Assert that the result matches the expected output | ||
expect(result.toNumber()).toEqual(expectedOutput); | ||
}); | ||
|
||
// Add more test cases as needed | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
function relu(input) { | ||
// If input is greater than or equal to zero, return input; otherwise, return zero. | ||
return input.greaterThanOrEqual(0).ifElse(input, new Field(0)); | ||
} |