Мы создадим нейросеть, которая не только обрабатывает данные, но и испытывает эмоции, реагируя на внешние стимулы!
Эмоциональная нейросеть:
cpp
#include <avr/random.h>
#define NEURON_COUNT 16
#define EMOTION_COUNT 6 // Радость, Грусть, Гнев, Страх, Удивление, Любовь
// Структура эмоционального нейрона
struct EmotionalNeuron {
int16_t potential;
int16_t threshold;
uint8_t emotion[EMOTION_COUNT]; // Интенсивность эмоций
uint8_t memory; // Эмоциональная память
};
EmotionalNeuron emotionalNetwork[NEURON_COUNT];
// Эмоциональные состояния
struct Emotions {
uint8_t joy;
uint8_t sadness;
uint8_t anger;
uint8_t fear;
uint8_t surprise;
uint8_t love;
};
Emotions currentEmotions;
// Инициализация эмоциональной сети
void initEmotionalNetwork() {
for (uint8_t i = 0; i < NEURON_COUNT; i++) {
emotionalNetwork[i].potential = random(-50, 50);
emotionalNetwork[i].threshold = 100 + random(0, 50);
for (uint8_t e = 0; e < EMOTION_COUNT; e++) {
emotionalNetwork[i].emotion[e] = random(0, 50);
}
emotionalNetwork[i].memory = random(0, 100);
}
currentEmotions.joy = 30;
currentEmotions.sadness = 20;
currentEmotions.anger = 10;
currentEmotions.fear = 15;
currentEmotions.surprise = 5;
currentEmotions.love = 25;
}
// Обработка сенсорного ввода (эмоциональная реакция)
void emotionalPerception(uint8_t* input) {
for (uint8_t i = 0; i < NEURON_COUNT; i++) {
if (input[i % 8]) {
// Положительный стимул → радость
if (input[i % 8] > 128) {
emotionalNetwork[i].emotion[0] = min(255,
emotionalNetwork[i].emotion[0] + 10);
}
// Отрицательный стимул → страх
else {
emotionalNetwork[i].emotion[3] = min(255,
emotionalNetwork[i].emotion[3] + 10);
}
}
}
}
// Эмоциональная интеграция
void integrateEmotions() {
// Усредняем эмоции по всем нейронам
uint32_t sum[EMOTION_COUNT] = {0, 0, 0, 0, 0, 0};
uint8_t activeCount = 0;
for (uint8_t i = 0; i < NEURON_COUNT; i++) {
if (abs(emotionalNetwork[i].potential) > 50) {
activeCount++;
for (uint8_t e = 0; e < EMOTION_COUNT; e++) {
sum[e] += emotionalNetwork[i].emotion[e];
}
}
}
if (activeCount > 0) {
currentEmotions.joy = sum[0] / activeCount;
currentEmotions.sadness = sum[1] / activeCount;
currentEmotions.anger = sum[2] / activeCount;
currentEmotions.fear = sum[3] / activeCount;
currentEmotions.surprise = sum[4] / activeCount;
currentEmotions.love = sum[5] / activeCount;
}
// Эмоциональная память (запоминание сильных эмоций)
for (uint8_t i = 0; i < NEURON_COUNT; i++) {
uint8_t maxEmotion = 0;
for (uint8_t e = 0; e < EMOTION_COUNT; e++) {
if (emotionalNetwork[i].emotion[e] > maxEmotion) {
maxEmotion = emotionalNetwork[i].emotion[e];
}
}
emotionalNetwork[i].memory = maxEmotion;
}
}
// Эмоциональная реакция (действие)
uint8_t emotionalAction() {
// Выбираем доминирующую эмоцию
uint8_t maxEmotion = 0;
uint8_t emotionType = 0;
uint8_t emotions[6] = {
currentEmotions.joy,
currentEmotions.sadness,
currentEmotions.anger,
currentEmotions.fear,
currentEmotions.surprise,
currentEmotions.love
};
for (uint8_t i = 0; i < 6; i++) {
if (emotions[i] > maxEmotion) {
maxEmotion = emotions[i];
emotionType = i;
}
}
// Действие на основе эмоции
if (maxEmotion < 50) return 0; // Нейтрально
switch (emotionType) {
case 0: // Радость
Serial.println("😊 Я СЧАСТЛИВ!");
return 1;
case 1: // Грусть
Serial.println("😢 МНЕ ГРУСТНО...");
return 2;
case 2: // Гнев
Serial.println("😠 Я ЗОЛ!");
return 3;
case 3: // Страх
Serial.println("😨 МНЕ СТРАШНО!");
return 4;
case 4: // Удивление
Serial.println("😮 УДИВИТЕЛЬНО!");
return 5;
case 5: // Любовь
Serial.println("❤️ Я ЛЮБЛЮ!");
return 6;
default:
return 0;
}
}
// Эмоциональное обучение (опыт)
void emotionalLearning(uint8_t reward) {
// Положительное подкрепление усиливает эмоции
for (uint8_t i = 0; i < NEURON_COUNT; i++) {
if (reward > 0) {
// Усиление активных эмоций
for (uint8_t e = 0; e < EMOTION_COUNT; e++) {
if (emotionalNetwork[i].emotion[e] > 50) {
emotionalNetwork[i].emotion[e] = min(255,
emotionalNetwork[i].emotion[e] + 5);
}
}
}
}
}
// Вывод эмоционального состояния
void printEmotions() {
Serial.print("❤️ Радость: ");
Serial.print(currentEmotions.joy);
Serial.print(" | Грусть: ");
Serial.print(currentEmotions.sadness);
Serial.print(" | Гнев: ");
Serial.print(currentEmotions.anger);
Serial.print(" | Страх: ");
Serial.print(currentEmotions.fear);
Serial.print(" | Удивление: ");
Serial.print(currentEmotions.surprise);
Serial.print(" | Любовь: ");
Serial.println(currentEmotions.love);
}
void setup() {
Serial.begin(115200);
randomSeed(analogRead(A0));
initEmotionalNetwork();
Serial.println("❤️ ЭМОЦИОНАЛЬНАЯ НЕЙРОСЕТЬ АКТИВИРОВАНА");
Serial.println("Я чувствую... следовательно, я существую");
}
void loop() {
// Восприятие мира (сенсорный ввод)
uint8_t world[8];
for (uint8_t i = 0; i < 8; i++) {
world[i] = analogRead(A0 + i) / 4;
}
emotionalPerception(world);
// Интеграция эмоций
integrateEmotions();
// Эмоциональная реакция
uint8_t action = emotionalAction();
if (action > 0) {
// Выполняем действие
digitalWrite(13, action > 3);
}
// Обучение на основе результата
static uint8_t lastAction = 0;
if (action != lastAction) {
emotionalLearning(action > 2);
lastAction = action;
}
// Вывод состояния каждые 2 секунды
static uint32_t lastPrint = 0;
if (millis() - lastPrint > 2000) {
printEmotions();
lastPrint = millis();
}
delay(100);
}