RedRBF::RedRBF(unsigned int dimension, unsigned int cantidad_rbf, unsigned int cantidad_perceptron, float eta) { this->dimension = dimension; this->cantidad_rbf = cantidad_rbf; this->cantidad_perceptron = cantidad_perceptron; for (unsigned int i = 0; i < cantidad_rbf; i++) { NeuronaRBF neu(this->dimension); this->neuronasRBF.push_back(neu); } for (unsigned int i = 0; i < cantidad_perceptron; i++) { NeuronaPerceptron neu(this->cantidad_rbf+1, eta); this->neuronasPerceptron.push_back(neu); } }
strahl ebene::brech(strahl& s, long double nbr, vektor& os) { vektor st,rn,ra,y,x; long double sbeta, salpha,z; //sin(Brechungswinkel), sin(Einfallswinkel), //effektive Brechzahl long double a,b; //Der Richtungsvektor des gebrochenen Strahles ist um den Winkel beta-alpha //in der Brechebene(E(s.gri(),Normalenvektor,os)) gedreht. ra=s.gri(); x=n.norm(); //Festlegung des ersten Richtungsvektors der Ebene in der gedreht //wird y=s.gri()-x*(x*s.gri()); y=y.norm(); //Festlegung des zweiten Richtungsvektors auf der Ebene, in der //gedreht wird. a=x*ra; b=y*ra; salpha=sin(phi(s)); //Winkel alpha z=s.gn()/nbr; //Effektive Brechzahl // if(z*salpha<=1) sbeta=z*salpha; rn=x*sqrt(1-sbeta*sbeta)*sign(a)+y*sbeta*sign(b); strahl neu(rn,os,nbr); return neu; }
/***** * Leistung: Berechnet zum im Punkt os einfallenden Strahl s den an der Ebene * reflektierenden Strahl * Übergabe: Referenz auf strahl s, Referenz auf vektor os * Rückgabe: reflektierter Strahl *****/ strahl ebene::refl(strahl& s, vektor& os) { vektor rn,x,ra; x=n.norm(); ra=s.gri(); rn=ra-((x*(ra*x))*2.0f); strahl neu(rn,os,s.gn()); return neu; }
Tkatbasis::Tkatbasis(treal l, treal d, treal w, QString n, int x_, int y_){ neu(); nummer=getknummer(); name=n; x=x_; y=y_; laenge=l; durchmesser=d; wandstaerke=w; }
farbe_rgb farbe_rgb::operator+(farbe_rgb zwei) { if((r+zwei.r>1)||(g+zwei.g>1)||(b+zwei.b>1)) return (*this); else { farbe_rgb neu(r+zwei.r,g+zwei.g,b+zwei.b); return neu; } }
farbe_rgb farbe_rgb::operator*(long double s) { if((s>1) || (s<0)) //Streckung nicht erlaubt return (*this); else { farbe_rgb neu(r*s,g*s,b*s); return neu; } }
Capa::Capa(int _nc,int _nn,float **_izq,float **_der) { num_capa=_nc; num_neuronas=_nn; izq=_izq; der=_der; for(int i=0;i<_nn;i++){ Neurona neu(_nc,i); neuronas.push_back(neu); } }
/** * @brief Hauptprogramm */ int main(int argc, char* argv[]) { char *end; int z; sem_init(); if(argc > 1) { if(!strcmp("-l", argv[1])) { if(argc == 3) liste(argv[2]); else if(argc == 2) liste(NULL); else rtfm(argv); } else if(!strcmp("-n", argv[1])) { if(argc == 4) neu(argv[2], argv[3]); else rtfm(argv); } else if(!strcmp("-z", argv[1])) { if(argc == 4) { z = strtoul(argv[3], &end, 0); if(argv[3] == end) { fprintf(stderr, "%s: Keine Zahl: %s\n", argv[0], argv[3]); exit(1); } zuschlag(argv[2], z); } else rtfm(argv); } else if(!strcmp("-d", argv[1])) { if(argc == 3) rechnung(argv[2]); else rtfm(argv); } else rtfm(argv); } else { rtfm(argv); } exit(0); }
QString operator+(const ProString &one, const ProString &two) { if (two.m_length) { if (!one.m_length) { return two.toQString(); } else { QString neu(one.m_length + two.m_length, Qt::Uninitialized); ushort *ptr = (ushort *)neu.constData(); memcpy(ptr, one.m_string.constData() + one.m_offset, one.m_length * 2); memcpy(ptr + one.m_length, two.m_string.constData() + two.m_offset, two.m_length * 2); return neu; } } return one.toQString(); }
/*! * \brief ProString::prepareExtend * \param extraLen number of new characters to be added * \param thisTarget offset to which current contents should be moved * \param extraTarget offset at which new characters will be added * \return pointer to storage location for new characters * * Prepares the string for adding new characters. * If the string is detached and has enough space, it will be changed in place. * Otherwise, it will be replaced with a new string object, thus detaching. * In either case, the hash will be reset. */ QChar *ProString::prepareExtend(int extraLen, int thisTarget, int extraTarget) { if (m_string.isDetached() && m_length + extraLen <= m_string.capacity()) { m_string.reserve(0); // Prevent the resize() below from reallocating QChar *ptr = (QChar *)m_string.constData(); if (m_offset != thisTarget) memmove(ptr + thisTarget, ptr + m_offset, m_length * 2); ptr += extraTarget; m_offset = 0; m_length += extraLen; m_string.resize(m_length); m_hash = 0x80000000; return ptr; } else { QString neu(m_length + extraLen, Qt::Uninitialized); QChar *ptr = (QChar *)neu.constData(); memcpy(ptr + thisTarget, m_string.constData() + m_offset, m_length * 2); ptr += extraTarget; *this = ProString(neu); return ptr; } }
//Genera la estructura, llamado por los constructores. Crea las neuronas y se las guarda void Red::structureGenerator( float tasa_aprendizaje, unsigned int int_funcion_activacion) { unsigned int n,m,ne,me; n = adyacencias.size(); //Filas assert(n > 0); //Control de que sea una matriz m = adyacencias[0].size(); //Columnas assert(m > 0 && m == n); //Control de que sea una matriz y cuadrada ne = adyacencias_entradas.size(); //Filas de adyacencia assert(ne > 0); //Control de que sea una matriz me = adyacencias_entradas[0].size(); assert(me > 0 && me == n); //Control de que sea una matriz y que esten definidas // la misma cantidad de neuronas en adyacencias_entradas this->multicapa = false; //Instanciamos las neuronas, para ello debemos contar su dimensión. for (unsigned int i = 0; i < n; i++) { unsigned int dimension = 0; //Cuento la dimension debida a Neuronas for (unsigned int j = 0; j < n; j++) { if (this->adyacencias[j][i]) { //comprobar i != j ? dimension++; this->multicapa = true; //Detectamos que es multicapa ( ver despues, el tema de la identidad, osea que tiene una sola capa pero es recursivo) } } //Cuento la dimension debida a entradas for (unsigned int j = 0; j < ne; j++) { if (this->adyacencias_entradas[j][i]) { dimension++; } } Neurona neu(dimension, -0.5, 0.5, int_funcion_activacion , tasa_aprendizaje); this->neuronas.push_back(neu); } //Generaremos la estructura de la red en forma matricial unsigned int na = adyacencias_entradas.size(); //Cantidad de entradas if (na > 0) { unsigned int ma = adyacencias_entradas[0].size(); //Cantidad de Neuronas //Detectamos la primera capa de neuronas (conectadas con entradas) std::vector<unsigned int> temp; for (unsigned int i = 0; i < ma; i++ ) { for (unsigned int j=0; j < na ; j++) { if (adyacencias_entradas[j][i]) { //La neurona i está conectada a la entrada j temp.push_back(i); break; } } } //pushbackeamos las entradas a la estructura this->estructura.push_back(temp); while (true) { std::vector<unsigned int> temp2; for (unsigned int i = 0; i < temp.size(); i++) { std::vector<unsigned int> V; this->getNext(temp[i], V); temp2.insert(temp2.end(), V.begin(), V.end()); } if (temp2.size() == 0) break; //No hay más capas porque a la derecha no hay nada. //Eliminamos duplicados std::sort(temp2.begin(), temp2.end()); std::vector<unsigned int>::iterator it = std::unique(temp2.begin(), temp2.end()); temp2.resize(it - temp2.begin()); this->estructura.push_back(temp2); temp = temp2; } } //Inicializa el map for (unsigned int i = 0; i < this->estructura.size(); i++) { for (unsigned int j = 0; j < this->estructura[i].size(); j++) { unsigned int id_neurona = this->estructura[i][j]; std::vector<float> v_t; unsigned int cantidad_pesos = this->neuronas[id_neurona].getW().size(); //le insertamos todos ceros for (unsigned int k = 0; k < cantidad_pesos; k++) { v_t.push_back(0.0); } this->deltas_w_ji[ id_neurona ] = v_t; } } }
farbe_rgb farbe_rgb::neg() { farbe_rgb neu(1-r,1-g,1-b); return neu; }