summaryrefslogtreecommitdiff
path: root/perceptron.c
diff options
context:
space:
mode:
Diffstat (limited to 'perceptron.c')
-rw-r--r--perceptron.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/perceptron.c b/perceptron.c
new file mode 100644
index 0000000..0d0d35a
--- /dev/null
+++ b/perceptron.c
@@ -0,0 +1,53 @@
+#include <stdio.h>
+
+// perceptron to decide if a person is friend or foe
+// values range from 0 to 10
+
+struct weights {
+ float nice;
+ float intelligent;
+ float funny;
+ float based;
+};
+
+struct person {
+ int nice;
+ int intelligent;
+ int funny;
+ int based;
+ char name[64];
+};
+
+int perceptron(struct weights *weights, struct person *person, float activation_value);
+
+int main(void)
+{
+ struct person tim = {8, 8, 6, 10, "Tim"};
+ struct person lara = {3, 3, 4, 1, "Lara"};
+ struct person finja = {10, 6, 7, 8, "Finja"};
+ struct person marlon = {8, 6, 6, 5, "Marlon"};
+
+ struct weights personal_weights = {0.7, 0.5, 0.7, 1.5};
+ struct person perceptron_person = lara;
+ int decision;
+
+ decision = perceptron(&personal_weights, &perceptron_person, 0.6);
+ if (decision) {
+ printf("%s is your friend\n", perceptron_person.name);
+ } else {
+ printf("%s is your foe\n", perceptron_person.name);
+ }
+}
+
+int perceptron(struct weights *weights, struct person *person, float activation_value)
+{
+ float nice_value, intelligent_value, funny_value, based_value, general_value;
+
+ nice_value = weights->nice / 10 * person->nice;
+ intelligent_value = weights->intelligent / 10 * person->intelligent;
+ funny_value = weights->funny / 10 * person->funny;
+ based_value = weights->based / 10 * person->based;
+
+ general_value = (nice_value + intelligent_value + funny_value + based_value) / 4;
+ return (general_value > activation_value) ? 1 : 0;
+}