xxxxxxxxxx
// استيراد مكتبة TensorFlow.js إذا كنت تستخدم بيئة HTML
// تأكد من وجود السطر التالي في ملف HTML الخاص بك:
// <script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs"></script>
// بيانات الإدخال والمخرجات
const INPUT = [
[0, 0, 1],
[1, 1, 1],
[1, 0, 1],
[0, 1, 1]
];
const OUTPUT = [
[0],
[1],
[1],
[0]
];
// بناء نموذج الشبكة العصبية
const model = tf.sequential();
model.add(tf.layers.dense({
inputShape: [3],
units: 4,
activation: 'relu'
}));
model.add(tf.layers.dense({
units: 1,
activation: 'sigmoid'
}));
model.compile({
optimizer: 'adam',
loss: 'binaryCrossentropy',
metrics: ['accuracy']
});
// تحويل البيانات إلى Tensors
const inputTensor = tf.tensor2d(INPUT);
const outputTensor = tf.tensor2d(OUTPUT);
// تدريب النموذج
async function trainModel() {
console.log("Training started...");
await model.fit(inputTensor, outputTensor, {
epochs: 100,
verbose: 1
});
console.log("Training complete!");
// توقع القيمة المفقودة X
const newInput = tf.tensor2d([[1, 0, 0]]);
const prediction = model.predict(newInput);
prediction.print(); // طباعة النتائج
}
// بدء التدريب
trainModel();