我正在尝试做一个分类器。
我是 AI 新手(即使我知道定义之类的东西),即使我知道一点 Python 编码,我也不知道如何正确地实现它(事实上,我已经 15 岁了)老!🙄🙄),但我对此的热情让我问了这个(可能是愚蠢的)问题。
是否存在从一组节点中随机选择节点的神经网络(以随机顺序和随机次数)?我知道这是来自 ML(或者可能是深度学习,我想),但我不知道如何从目前可用的算法中识别出这样的东西。如果你们都可以帮助我,那就太好了,因为我正准备发布一个 API 来编程我在 GitHub 上称为“Insane Mind”的模型,我想要一些帮助来了解我的努力是否没有结果。
作为参考,这里是代码:
from math import *
from random import *
class MachineError(Exception):
'''standard exception in the API'''
def __init__(self, stmt):
self.stmt = stmt
def sig(x):
'''Sigmoid function'''
return (exp(x) + 1)/exp(x)
class Graviton:
def __init__(self, weight, marker):
'''Basic unit in 'Insane Mind' algorithm
-------------------------------------
Graviton simply refers to a node in the algorithm.
I call it graviton because of the fact that it applies a weight
on the input to transform it, besides using the logistic function '''
self.weight = weight # Weight factor of the graviton
self.marker = marker # Marker to help in sorting
self.input = 0 # Input to the graviton
self.output = 0 # Output of the graviton
self.derivative = 0 # Derivative of the output
def process(self, input_to_machine):
'''processes the input (a bit of this is copied from the backprop algorithm'''
self.input = input_to_machine
self.output = (sig(self.weight * self.input) - 1)/(self.marker + 1)
self.derivative = (sig(self.input * self.weight) - 1) * self.input *self.output * (1- self.output)
return self.output
def get_derivative_at_input(self):
'''returns the derivative of the output'''
return self.derivative
def correct_self(self, learning_rate, error):
'''edits the weight'''
self.weight += -1 * error * learning_rate * self.get_derivative_at_input() * self.weight
class Insane_Mind:
def __init__(self, number_of_nodes):
'''initialiser for Insane_Mind class.
arguments : number_of_nodes : the number of nodes you want in the model'''
self.system = [Graviton(random(),i) for i in range(number_of_nodes)] # the actual system
self.system_size = number_of_nodes # number of nodes , or 'system size'
def output_sys(self, input_to_sys):
'''system output'''
self.output = input_to_sys
for i in range(self.system_size):
self.output = self.system[randint(0,self.system_size - 1 )].process(self.output)
return self.output
def train(self, learning_rate, wanted):
'''trains the system'''
self.cloned = [] # an array to keep the sorted elements during the sorting process below
order = [] # the array to make out the order of arranging the nodes
temp = {} # a temporary dictionary to pick the nodes from
for graviton in self.system:
temp.update({str(graviton.derivative): graviton.marker})
order = sorted(temp)
i = 0
error = wanted - self.output
for value in order:
self.cloned.append(self.system[temp[value]])
self.cloned[i].correct_self(learning_rate, error)
error *= self.cloned[i].derivative
i += 1
self.system = self.cloned
很抱歉没有MachineError
在我的代码中的任何地方使用该异常(我将在能够部署此 API 时使用它)。
为了更多地了解这个算法,这给出了随机输出(就像猜测一样)。猜测的数量从 1(对于具有一个节点的系统)、2(对于两个节点)等到无限数量的节点的无限猜测。
另外,我想尝试找出它有多少用处(如果这是从未被发现的东西,如果它可以在 ML 或深度学习的世界中找到一个好地方)以及它可以在哪里使用.
提前致谢。
批评(有明确的理由)也被接受。