-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clearer naming for partial derivatives
- Loading branch information
Showing
15 changed files
with
245 additions
and
93 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,39 @@ | ||
/** | ||
* Simple example network which learns to multiply input by two | ||
* | ||
* Input: 5, 3, 8 | ||
* Output: 10, 6, 16 | ||
*/ | ||
|
||
import _ from 'lodash'; | ||
|
||
import { | ||
DeferredInputFeed, | ||
DeferredMemoryInputFeed, | ||
Dense, | ||
Model, | ||
NDArray, | ||
} from '../src'; | ||
|
||
import { SampleGenerator } from './sample-generator'; | ||
|
||
|
||
export class DenseSimple2x extends SampleGenerator { | ||
public model(): Model { | ||
const model = new Model({ seed: this.params.seed }); | ||
|
||
model | ||
.input(1) | ||
.push(new Dense({ units: 3, activation: 'identity' }, 'hidden-1')) | ||
.push(new Dense({ units: 1, activation: 'identity' }, 'output')); | ||
|
||
return model; | ||
} | ||
|
||
|
||
public samples(count: number): DeferredInputFeed { | ||
return DeferredMemoryInputFeed.factory( | ||
_.times(count, n => ({ x: new NDArray([n]), y: new NDArray([n * 2]) })), | ||
); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './dense-2x'; | ||
export * from './dense-simple-2x'; | ||
export * from './sample-generator'; |
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
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
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
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
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
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,19 @@ | ||
import { Loss } from './loss'; | ||
import { Vector } from '../../math'; | ||
|
||
/** | ||
* Squared Error | ||
*/ | ||
export class SquaredError extends Loss { | ||
public calculate(yHat: Vector, y: Vector): number { | ||
// 0.5 * sum( ( yHat - y ) ^ 2 ) | ||
return 0.5 * yHat.sub(y).pow(2).sum(); | ||
} | ||
|
||
|
||
public gradient(yHat: Vector, y: Vector): Vector { | ||
return yHat.sub(y).pow(2).mul(0.5); | ||
// return yHat.sub(y); | ||
} | ||
} | ||
|
Oops, something went wrong.