//DignityMachine Core To Build From
class dignityMachine {
constructor(){
this.weights = [Math.random(), Math.random()]; //2 Inputs
this.bias = Math.random();
this.humility = 0.1;
}
//Activation function (Sigmoid algorithm)
sigmoid(x){
return 1 / (1+ Math.exp(-x));
}
prediction(inputs){
let sum = this.bias;
for (let i=0; i < inputs.length; i++){
sum += inputs[i] * this.weights[i];
}
return this.sigmoid(sum);
}
train(inputs, target){
const output = this.prediction(inputs);
const error = target - output;
for (let i = 0; i < this.weights.length; i++){
this.weights[i] += error * inputs[i] * this.humility;
}
this.bias += error * this.humility;
}
}
const dm = new dignityMachine();
for (let i=0; i < 20; i++) {
dm.train([0, 0], 0);
dm.train([1, 0], 0);
dm.train([0, 1], 0);
dm.train([1, 1], 1);
}
let humility = ["Empathy", "Give Charity", "Kindness", "Forgive", "Ask how you can help.", "Listen to person's experience amd story.", "Say a prayer", "Pray together", "Ensure needs of real food, real water, real sleep, real shelter, real clothing, real hygiene, real psychological need of safety, real need of belonging within social, peer, and family groupings are met."];
let random1 = humility[Math.floor(Math.random() * humility.length)];
let random2 = humility[Math.floor(Math.random() * humility.length)];
console.log("DM: ", dm.prediction(1,1));
console.log(dm.prediction(1,1) > 0.25 ? random1 : random2);