Skip to content

Commit

Permalink
Minor method additions
Browse files Browse the repository at this point in the history
  • Loading branch information
jr-garcia committed Jul 31, 2016
1 parent 968142b commit 1d42a85
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
33 changes: 31 additions & 2 deletions _MultiNEAT.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ cdef class Parameters:
def Load(self, filename):
self.thisptr.Load(filename)
def Save(self, filename):
self.thisptr.Load(filename)
self.thisptr.Save(filename)
def Reset(self):
self.thisptr.Reset()

Expand Down Expand Up @@ -605,6 +605,35 @@ cdef class NeuralNetwork:
def Clear(self):
self.thisptr.Clear()

def Save(self, const char* a_filename):
self.thisptr.Save(a_filename)

def Load(self, const char* a_filename):
return self.thisptr.Load(a_filename)

def NumInputs(self):
return self.thisptr.NumInputs()

def NumOutputs(self):
return self.thisptr.NumOutputs()

def AddNeuron(self, Neuron a_n):
self.thisptr.AddNeuron(deref(a_n.thisptr))

def AddConnection(self, Connection a_c):
self.thisptr.AddConnection(deref(a_c.thisptr))

def GetConnectionByIndex(self, unsigned int a_idx):
cdef cmn.Connection ncon= self.thisptr.GetConnectionByIndex(a_idx)
return pyConnectionFromReference(ncon)

def GetNeuronByIndex(self, unsigned int a_idx):
cdef cmn.Neuron nneur = self.thisptr.GetNeuronByIndex(a_idx)
return pyNeuronFromReference(nneur)

def SetInputOutputDimentions(self, const unsigned short a_i, const unsigned short a_o):
self.thisptr.SetInputOutputDimentions(a_i, a_o)

property num_inputs:
def __get__(self): return self.thisptr.m_num_inputs
def __set__(self, m_num_inputs): self.thisptr.m_num_inputs = m_num_inputs
Expand Down Expand Up @@ -812,7 +841,7 @@ cdef class Genome:
def BuildHyperNEATPhenotype(self, NeuralNetwork net, Substrate subst):
self.thisptr.BuildHyperNEATPhenotype(deref(net.thisptr), deref(subst.thisptr))

def Save(self, a_filename):
def Save(self, str a_filename):
self.thisptr.Save(a_filename)

def IsEvaluated(self):
Expand Down
17 changes: 17 additions & 0 deletions cMultiNeat.pxd
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from libcpp.vector cimport vector
from libcpp cimport bool
from libc.stdio cimport FILE

"""
#############################################
Expand Down Expand Up @@ -275,6 +276,20 @@ cdef extern from "src/NeuralNetwork.h" namespace "NEAT":
vector[double] Output()
void Clear()

# one-shot save/load
void Save(const char* a_filename)
bool Load(const char* a_filename)
# save/load from already opened files for reading/writing
void Save(FILE* a_file)

void AddNeuron(const Neuron& a_n)
void AddConnection(const Connection& a_c)
Connection GetConnectionByIndex(unsigned int a_idx) const
Neuron GetNeuronByIndex(unsigned int a_idx) const
void SetInputOutputDimentions(const unsigned short a_i, const unsigned short a_o)
unsigned int NumInputs() const
unsigned int NumOutputs() const


cdef extern from "src/Substrate.h" namespace "NEAT":
cdef cppclass Substrate:
Expand Down Expand Up @@ -350,6 +365,8 @@ cdef extern from "src/Genome.h" namespace "NEAT":
void BuildHyperNEATPhenotype(NeuralNetwork& net, Substrate& subst)

void Save(const char* a_filename)
# Saves this genome to an already opened file for writing
void Save(FILE* a_fstream);

bool m_Evaluated
bool IsEvaluated()
Expand Down

0 comments on commit 1d42a85

Please sign in to comment.