parent
a8a8dbaf2a
commit
7d5fa9e69a
4 changed files with 300 additions and 0 deletions
@ -0,0 +1,3 @@ |
|||||||
|
.node_modules |
||||||
|
/node_modules |
||||||
|
.codegpt |
@ -0,0 +1,159 @@ |
|||||||
|
const regression = require('regression'); |
||||||
|
|
||||||
|
// const readline = require('node:readline');
|
||||||
|
// const rl = readline.createInterface({
|
||||||
|
// input: process.stdin,
|
||||||
|
// output: process.stdout
|
||||||
|
// })
|
||||||
|
|
||||||
|
const data = [ |
||||||
|
[6,88], |
||||||
|
[10,71], |
||||||
|
[5,19], |
||||||
|
[9,59], |
||||||
|
[8,18], |
||||||
|
[3,77], |
||||||
|
[2,61], |
||||||
|
[1,53], |
||||||
|
[7,13], |
||||||
|
[4,40], |
||||||
|
] |
||||||
|
|
||||||
|
class Nemoodar{ |
||||||
|
data; |
||||||
|
first_length=0; |
||||||
|
algorithms={ |
||||||
|
"linear":{ |
||||||
|
data:[], |
||||||
|
enheraf:0, |
||||||
|
}, |
||||||
|
"exponential":{ |
||||||
|
data:[], |
||||||
|
enheraf:0, |
||||||
|
}, |
||||||
|
"power":{ |
||||||
|
data:[], |
||||||
|
enheraf:0, |
||||||
|
}, |
||||||
|
"logarithmic":{ |
||||||
|
data:[], |
||||||
|
enheraf:0, |
||||||
|
}, |
||||||
|
"polynomial2":{ |
||||||
|
data:[], |
||||||
|
enheraf:0, |
||||||
|
}, |
||||||
|
"polynomial3":{ |
||||||
|
data:[], |
||||||
|
enheraf:0, |
||||||
|
}, |
||||||
|
"polynomial4":{ |
||||||
|
data:[], |
||||||
|
enheraf:0, |
||||||
|
},"polynomial5":{ |
||||||
|
data:[], |
||||||
|
enheraf:0, |
||||||
|
} |
||||||
|
} |
||||||
|
constructor({data,predict=1,option="linear",n=2}){ |
||||||
|
console.log("option",option) |
||||||
|
this.data = [...data.sort((a,b)=> a[0] - b[0])]; |
||||||
|
this.first_length = this.data.length; |
||||||
|
for(let algo in this.algorithms){ |
||||||
|
switch(algo){ |
||||||
|
case "linear": |
||||||
|
this.algorithms[algo].data=this.linear([...data],predict); |
||||||
|
break; |
||||||
|
case "exponential": |
||||||
|
this.algorithms[algo].data=this.exponential([...data],predict) |
||||||
|
break; |
||||||
|
case "power": |
||||||
|
this.algorithms[algo].data=this.power([...data],predict) |
||||||
|
break; |
||||||
|
case "logarithmic": |
||||||
|
this.algorithms[algo].data=this.logarithmic([...data],predict) |
||||||
|
break; |
||||||
|
case "polynomial2": |
||||||
|
this.algorithms[algo].data=this.polynomial([...data],predict,2); |
||||||
|
break; |
||||||
|
case "polynomial3": |
||||||
|
this.algorithms[algo].data=this.polynomial([...data],predict,3); |
||||||
|
break; |
||||||
|
case "polynomial4": |
||||||
|
this.algorithms[algo].data=this.polynomial([...data],predict,4); |
||||||
|
break; |
||||||
|
case "polynomial5": |
||||||
|
this.algorithms[algo].data=this.polynomial([...data],predict,5); |
||||||
|
break; |
||||||
|
} |
||||||
|
} |
||||||
|
for(let algo in this.algorithms){ |
||||||
|
const theData = this.algorithms[algo].data; |
||||||
|
let sum = 0; |
||||||
|
for(let i=0;i<this.first_length;i++){ |
||||||
|
const first = this.data[i][1]; |
||||||
|
const second = theData[i][1]; |
||||||
|
sum += Math.pow(second-first,2); |
||||||
|
} |
||||||
|
this.algorithms[algo].enheraf = sum; |
||||||
|
} |
||||||
|
let min_enheraf = -1; |
||||||
|
let final_result = {}; |
||||||
|
|
||||||
|
for(let algo in this.algorithms){ |
||||||
|
if(min_enheraf==-1) min_enheraf=this.algorithms[algo].enheraf; |
||||||
|
if(this.algorithms[algo].enheraf<min_enheraf){ |
||||||
|
min_enheraf = this.algorithms[algo].enheraf; |
||||||
|
final_result = {"algorithm":algo,data:this.algorithms[algo].data,enheraf:this.algorithms[algo].enheraf}; |
||||||
|
} |
||||||
|
} |
||||||
|
console.log(final_result) |
||||||
|
return final_result; |
||||||
|
} |
||||||
|
linear(data,predict){ |
||||||
|
const result = regression.linear(data); |
||||||
|
return this.predict(result,predict) |
||||||
|
} |
||||||
|
|
||||||
|
exponential(data,predict){ |
||||||
|
const result = regression.exponential(data); |
||||||
|
return this.predict(result,predict) |
||||||
|
} |
||||||
|
|
||||||
|
power(data,predict){ |
||||||
|
const result = regression.power(data); |
||||||
|
return this.predict(result,predict) |
||||||
|
} |
||||||
|
|
||||||
|
logarithmic(data,predict){ |
||||||
|
const result = regression.logarithmic(data); |
||||||
|
return this.predict(result,predict) |
||||||
|
} |
||||||
|
polynomial(data,predict,n=2){ |
||||||
|
if(n<2) n=2; |
||||||
|
if(n>5) n=5; |
||||||
|
const result = regression.polynomial(data,{order: n}); |
||||||
|
return this.predict(result,predict) |
||||||
|
} |
||||||
|
predict(rgr,predict){ |
||||||
|
console.log(rgr.string); |
||||||
|
const newData = [] |
||||||
|
for(let i=0;i<predict+this.first_length;i++){ |
||||||
|
const predicted = rgr.predict(i+1); |
||||||
|
// console.log(`predicted value for ${predicted[0]+first_length} is ${predicted[1]}`)
|
||||||
|
newData.push(predicted); |
||||||
|
// this.data.push([predicted[0]+first_length,predicted[1]])
|
||||||
|
} |
||||||
|
return newData; |
||||||
|
// console.log(this.data.push)
|
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
new Nemoodar({data,predict:5,option:"logarithmic",n:2})
|
||||||
|
|
||||||
|
// linear
|
||||||
|
// exponential
|
||||||
|
// power
|
||||||
|
// logarithmic
|
||||||
|
// polynomial option:"polynomial",n:2 (example)
|
||||||
|
|
@ -0,0 +1,122 @@ |
|||||||
|
{ |
||||||
|
"name": "1-nemoodar", |
||||||
|
"version": "1.0.0", |
||||||
|
"lockfileVersion": 3, |
||||||
|
"requires": true, |
||||||
|
"packages": { |
||||||
|
"": { |
||||||
|
"name": "1-nemoodar", |
||||||
|
"version": "1.0.0", |
||||||
|
"license": "ISC", |
||||||
|
"dependencies": { |
||||||
|
"axios": "^1.7.9", |
||||||
|
"regression": "^2.0.1" |
||||||
|
} |
||||||
|
}, |
||||||
|
"node_modules/asynckit": { |
||||||
|
"version": "0.4.0", |
||||||
|
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", |
||||||
|
"integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", |
||||||
|
"license": "MIT" |
||||||
|
}, |
||||||
|
"node_modules/axios": { |
||||||
|
"version": "1.7.9", |
||||||
|
"resolved": "https://registry.npmjs.org/axios/-/axios-1.7.9.tgz", |
||||||
|
"integrity": "sha512-LhLcE7Hbiryz8oMDdDptSrWowmB4Bl6RCt6sIJKpRB4XtVf0iEgewX3au/pJqm+Py1kCASkb/FFKjxQaLtxJvw==", |
||||||
|
"license": "MIT", |
||||||
|
"dependencies": { |
||||||
|
"follow-redirects": "^1.15.6", |
||||||
|
"form-data": "^4.0.0", |
||||||
|
"proxy-from-env": "^1.1.0" |
||||||
|
} |
||||||
|
}, |
||||||
|
"node_modules/combined-stream": { |
||||||
|
"version": "1.0.8", |
||||||
|
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", |
||||||
|
"integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", |
||||||
|
"license": "MIT", |
||||||
|
"dependencies": { |
||||||
|
"delayed-stream": "~1.0.0" |
||||||
|
}, |
||||||
|
"engines": { |
||||||
|
"node": ">= 0.8" |
||||||
|
} |
||||||
|
}, |
||||||
|
"node_modules/delayed-stream": { |
||||||
|
"version": "1.0.0", |
||||||
|
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", |
||||||
|
"integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", |
||||||
|
"license": "MIT", |
||||||
|
"engines": { |
||||||
|
"node": ">=0.4.0" |
||||||
|
} |
||||||
|
}, |
||||||
|
"node_modules/follow-redirects": { |
||||||
|
"version": "1.15.9", |
||||||
|
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.9.tgz", |
||||||
|
"integrity": "sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ==", |
||||||
|
"funding": [ |
||||||
|
{ |
||||||
|
"type": "individual", |
||||||
|
"url": "https://github.com/sponsors/RubenVerborgh" |
||||||
|
} |
||||||
|
], |
||||||
|
"license": "MIT", |
||||||
|
"engines": { |
||||||
|
"node": ">=4.0" |
||||||
|
}, |
||||||
|
"peerDependenciesMeta": { |
||||||
|
"debug": { |
||||||
|
"optional": true |
||||||
|
} |
||||||
|
} |
||||||
|
}, |
||||||
|
"node_modules/form-data": { |
||||||
|
"version": "4.0.1", |
||||||
|
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.1.tgz", |
||||||
|
"integrity": "sha512-tzN8e4TX8+kkxGPK8D5u0FNmjPUjw3lwC9lSLxxoB/+GtsJG91CO8bSWy73APlgAZzZbXEYZJuxjkHH2w+Ezhw==", |
||||||
|
"license": "MIT", |
||||||
|
"dependencies": { |
||||||
|
"asynckit": "^0.4.0", |
||||||
|
"combined-stream": "^1.0.8", |
||||||
|
"mime-types": "^2.1.12" |
||||||
|
}, |
||||||
|
"engines": { |
||||||
|
"node": ">= 6" |
||||||
|
} |
||||||
|
}, |
||||||
|
"node_modules/mime-db": { |
||||||
|
"version": "1.52.0", |
||||||
|
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", |
||||||
|
"integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", |
||||||
|
"license": "MIT", |
||||||
|
"engines": { |
||||||
|
"node": ">= 0.6" |
||||||
|
} |
||||||
|
}, |
||||||
|
"node_modules/mime-types": { |
||||||
|
"version": "2.1.35", |
||||||
|
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", |
||||||
|
"integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", |
||||||
|
"license": "MIT", |
||||||
|
"dependencies": { |
||||||
|
"mime-db": "1.52.0" |
||||||
|
}, |
||||||
|
"engines": { |
||||||
|
"node": ">= 0.6" |
||||||
|
} |
||||||
|
}, |
||||||
|
"node_modules/proxy-from-env": { |
||||||
|
"version": "1.1.0", |
||||||
|
"resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", |
||||||
|
"integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==", |
||||||
|
"license": "MIT" |
||||||
|
}, |
||||||
|
"node_modules/regression": { |
||||||
|
"version": "2.0.1", |
||||||
|
"resolved": "https://registry.npmjs.org/regression/-/regression-2.0.1.tgz", |
||||||
|
"integrity": "sha512-A4XYsc37dsBaNOgEjkJKzfJlE394IMmUPlI/p3TTI9u3T+2a+eox5Pr/CPUqF0eszeWZJPAc6QkroAhuUpWDJQ==", |
||||||
|
"license": "MIT" |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,16 @@ |
|||||||
|
{ |
||||||
|
"name": "1-nemoodar", |
||||||
|
"version": "1.0.0", |
||||||
|
"main": "index.js", |
||||||
|
"scripts": { |
||||||
|
"test": "echo \"Error: no test specified\" && exit 1" |
||||||
|
}, |
||||||
|
"keywords": [], |
||||||
|
"author": "", |
||||||
|
"license": "ISC", |
||||||
|
"description": "", |
||||||
|
"dependencies": { |
||||||
|
"axios": "^1.7.9", |
||||||
|
"regression": "^2.0.1" |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue