Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
5d69739
chore: add eslint, prettier (code formating)
Twince Jul 27, 2025
b30c92d
build: add vite
Twince Jul 27, 2025
1ddc1ce
chore: add pnpm
Twince Jul 27, 2025
a3b6bd7
chore: add tsconfig
Twince Jul 27, 2025
a27252a
chor: add path on jsconfig
Twince Jul 27, 2025
a9f0797
chore: add gitignore
Twince Jul 27, 2025
777e6b7
refactor: vite의 root 기준을 준수하기 위해 index.html 위치 변경
Twince Jul 27, 2025
75a0224
migratoin: `QueryProcessController`, `throttle`, `NueralNetworkBase`를…
Twince Jul 27, 2025
24f10ea
chore: 상수 및 캔버스의 type 지정
Twince Jul 27, 2025
cbdde7d
rename: vite의 entry 포인트를 위한 이름 변경
Twince Jul 27, 2025
c1bfc4f
chore: 코드 포맷팅 및 interface 공통화를 위한 clear 기능 추가(canvas)
Twince Jul 27, 2025
ccab050
refactor: migration to typescript(WIP)
Twince Aug 6, 2025
7e86c81
build: package, pnpm-lock 내용 추가
Twince Aug 6, 2025
54ccb9d
chore: tsconfig 'allowImportingTsExtensions' 옵션 추가
Twince Aug 6, 2025
1c7769e
migration: 캔버스 핸들링 코드 리팩토링(WIP)
Twince Aug 6, 2025
d7f0725
chore: 설명 주석 추가
Twince Aug 6, 2025
a5874df
refactor: DrawingEventHandler 리팩토링
Twince Aug 6, 2025
a88d829
refactor: migration activation ops
Twince Aug 7, 2025
7cc8338
refactor: canvas migration to Typescript
Twince Aug 7, 2025
54db197
chore: 오타 수정
Twince Aug 9, 2025
40fd0b9
fix: BoundingBox의 오브젝트 좌표를 외부에서 접근할 수 있도록 수정
Twince Aug 9, 2025
9cf8460
chore: drawingEvent 관련 네이밍 변경
Twince Aug 16, 2025
dd86942
refactor: BoundingBox의 캡슐화를 위한 getter 추가
Twince Aug 16, 2025
fcd057d
chore: js to ts
Twince Aug 16, 2025
9911f1d
refactor: entryPoint의 일관성을 위해 DrawingEventHandler의 선언 위치 변경
Twince Aug 16, 2025
ec63410
refactor: jsconfig path 변경
Twince Aug 16, 2025
848c866
feat: canvas clear 기능 추가
Twince Aug 16, 2025
75a8e5f
feat: type 오류 및 잘못된 type 수정
Twince Aug 16, 2025
43fae54
refactor: migration to Typescript
Twince Aug 16, 2025
22e7c40
chore: canvas 초기화 이벤트 추가
Twince Aug 16, 2025
c73fbc6
fix: 잘못된 type 수정
Twince Aug 16, 2025
c07e748
chore: path alias 지정 및 변경
Twince Aug 16, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"env": {
"browser": true,
"es2021": true
},
"extends": [
"eslint:recommended",
"plugin:prettier/recommended"
],
"plugins": ["prettier"],
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"rules": {
"prettier/prettier": "error",
"no-unused-vars": "warn",
"no-console": "off"
}
}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
dev/train/trainData/mnist/mnistTraindata_large.js
dev/train/trainData/mnist/mnist_train.csv
node_modules
dist
build
*.min.js
48 changes: 48 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/prettier.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"printWidth": 100,
"tabWidth": 4,
"trailingComma": "all",
"singleQuote": true,
"semi": true
}
43 changes: 30 additions & 13 deletions dev/train/Trainer.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,44 @@
import { NeuralNetworkBase } from "../../src/core/NeuralNetworkBase.js";
import { NeuralNetworkBase } from '../../src/core/NeuralNetworkBase.ts';

// matrix operations
import {matrixMultiply, transposeMatrix} from "../../src/core/ops/matrixOps.js";
import { matrixMultiply, transposeMatrix } from '../../src/core/ops/matrixOps.ts';

export class Trainer extends NeuralNetworkBase {
train(inputs, targets){
train(inputs, targets) {
// CNN operations
const { finalOutputs, hiddenOutputs } = this.feedForward(inputs);
// calculate errors
const output_errors = targets.map((v, idx) => v - finalOutputs[idx]).map(v => [v]); // 출력 계층의 오차를 목표값 - 출력값으로 지정
const output_errors = targets.map((v, idx) => v - finalOutputs[idx]).map((v) => [v]); // 출력 계층의 오차를 목표값 - 출력값으로 지정
const hidden_errors = matrixMultiply(transposeMatrix(this.W_hiddenToOutput), output_errors); // 은닉 계층의 오차를 은닉-> 출력 계층의 가중치값과(W_hiddenToOutput.T) 출력 계층의 오차들을 재조합하여 계산

// activation function derivative
const activationDerivative_HtO = finalOutputs.map(v => 1.0 - v).map((v, idx) => v * finalOutputs[idx]); // hidden to output derivative
const outputGradient = activationDerivative_HtO.map((v, idx) => v * output_errors[idx]).map(v => [v]);
const W_HtO_Update = matrixMultiply(outputGradient, transposeMatrix(hiddenOutputs)).map(array => array.map(v => v * this.learningRate)); // 오차값을 이용해 은닉 계층과 출력 계층간의 가중치 업데이트
const activationDerivative_HtO = finalOutputs
.map((v) => 1.0 - v)
.map((v, idx) => v * finalOutputs[idx]); // hidden to output derivative
const outputGradient = activationDerivative_HtO
.map((v, idx) => v * output_errors[idx])
.map((v) => [v]);
const W_HtO_Update = matrixMultiply(outputGradient, transposeMatrix(hiddenOutputs)).map(
(array) => array.map((v) => v * this.learningRate),
); // 오차값을 이용해 은닉 계층과 출력 계층간의 가중치 업데이트

const activationDerivative_ItH = hiddenOutputs.map(v => 1.0 - v).map((v, idx) => v * hiddenOutputs[idx]);
const hiddenGradient = activationDerivative_ItH.map((v, idx) => v * hidden_errors[idx]).map(v => [v]);
const W_ItH_update = matrixMultiply(hiddenGradient, transposeMatrix(inputs.map(v => [v]))).map(array => array.map(v => v * this.learningRate));
const activationDerivative_ItH = hiddenOutputs
.map((v) => 1.0 - v)
.map((v, idx) => v * hiddenOutputs[idx]);
const hiddenGradient = activationDerivative_ItH
.map((v, idx) => v * hidden_errors[idx])
.map((v) => [v]);
const W_ItH_update = matrixMultiply(
hiddenGradient,
transposeMatrix(inputs.map((v) => [v])),
).map((array) => array.map((v) => v * this.learningRate));

// update weights
this.W_hiddenToOutput = this.W_hiddenToOutput.map((row, i)=> row.map((v, j) => v + W_HtO_Update[i][j]));
this.W_inputToHidden = this.W_inputToHidden.map((row, i)=> row.map((v, j) => v + W_ItH_update[i][j]));
this.W_hiddenToOutput = this.W_hiddenToOutput.map((row, i) =>
row.map((v, j) => v + W_HtO_Update[i][j]),
);
this.W_inputToHidden = this.W_inputToHidden.map((row, i) =>
row.map((v, j) => v + W_ItH_update[i][j]),
);
}
}
}
9 changes: 3 additions & 6 deletions public/index.html → index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Neural Network Visualization</title>
<script type="module" src="../src/index.js"></script>
<script src="../modernizr-custom.js"></script>
<script src="../modernizr-custom.js"></script>
<script type="module" src="src/main.ts"></script>
<script src="modernizr-custom.js"></script>
<link rel="stylesheet" href="/src/view/styles/settings.css">
</head>
<body>
Expand All @@ -21,9 +20,7 @@
<canvas id="perceptron"></canvas>
</section>
<section id="userInputSection">
<canvas style="position: fixed; left:0; top: 0;" id="resizeCanvas"></canvas>
<canvas style="position: fixed;" id="alignCanvas"></canvas>
<canvas id="pathTrackingCanvas"></canvas>
<button id="clear">clear canvas</button>
<canvas class="userInputCanvas" id="userInputCanvas"></canvas>
</section>
</div>
Expand Down
5 changes: 2 additions & 3 deletions jsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{
"compilerOptions": {
"baseUrl": "src",
"baseUrl": "./src",
"paths": {
"@controller/*": ["controller/*"],
"@view/*": ["view/*"]
"@/*": ["*"]
}
},
"include": ["src"]
Expand Down
21 changes: 17 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,22 @@
"version": "1.0.0",
"type": "module",
"description": "",
"main": "public/index.html",
"main": "index.html",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "vite",
"build": "tsc && vite build",
"preview": "vite preview",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"format": "prettier --write ."
},
"private": true
}
"private": true,
"devDependencies": {
"eslint": "^9.32.0",
"eslint-config-prettier": "^10.1.8",
"eslint-plugin-prettier": "^5.5.3",
"prettier": "3.6.2",
"vite": "^7.0.6"
}
}
Loading