void ANN::train(const std::vector<double>& instance, const std::vector<double>& expected, std::vector<double>& result ){ activate( instance, result ); std::vector<double> error; // Two delta vectors to std::vector<double> delta1; std::vector<double> delta2; // Matricies for forward synapse std::vector<double> ones(network[network.size()-1].size(), 1.0); std::vector<std::vector<double>*> fs1; std::vector<std::vector<double>*> fs2; bool deltaSet = false; // Flags for deltas calculateError( expected, result, error ); //std::cout << "Error: " << error[0] << std::endl; //std::cout << "Error: " << error[1] << std::endl; //std::cout << "Error: " << error[2] << std::endl; for( int i = network.size() - 1; i >= 0; i--){ // Get forward synapse before back prop if( !deltaSet ){ deltaSet = true; delta1.clear(); if( i != 0 ){ getFS(i - 1, fs2); } } else{ deltaSet = false; delta2.clear(); if( i != 0 ){ getFS(i - 1, fs1); } } for( int j = 0; j < network[i].size(); j++ ){ // If output layer. Delta = error //std::cout << "I: " << i << " J: " << j << std::endl; if( i == network.size() - 1){ delta1.push_back(network[i][j]->backProp(error, ones)); } else{ // Use second delta if odd i if( !deltaSet ){ //std::cout << "HERE" << std::endl; delta2.push_back(network[i][j]->backProp(delta1, *fs2[j])); } else{ delta1.push_back(network[i][j]->backProp(delta2, *fs1[j])); } } } } // clear vector for( std::vector<std::vector<double>*>::iterator itr = fs1.begin(); itr != fs1.end(); ++itr){ delete (*itr); } // clear vector for( std::vector<std::vector<double>*>::iterator itr = fs2.begin(); itr != fs2.end(); ++itr){ delete (*itr); } }
// rpc call that takes a 4 byte pointer and 2 byte len and a block of data then an fn, and writes that to a file at that pos int rpcfswriteinto(void *data, unsigned int datalen, KnownClient *client, void *rbuffer, unsigned int *rlen) { *rlen = 0; unsigned int pos = readUnsignedNumber(data, 4); unsigned int m = readUnsignedNumber(data + 4, 2); fs::FS *mountpoint = getFS((char *)data +m+ 6); //Skip the first slash if any(Assume mountpoint name is at least 2 chars) //Then get the slash after that. char *fn = strchr((char *)data + m + 7, '/'); if (mountpoint == 0) { RPC_ERR(3, (String("Nonexistant filesystem ") + String((char *)data+m)).c_str()); } data += 6; File file; if (mountpoint->exists(fn)) { file = mountpoint->open(fn, "r+"); if (file.size() <= pos) { file.close(); file = mountpoint->open(fn, "a"); } else { file.seek(pos); } } else { file = mountpoint->open(fn, "w+"); } if (!file) { file.close(); RPC_ERR(1, "Selected path is a directory or could not be opened"); } #ifdef ESP32 if (!file || file.isDirectory()) { file.close(); //eVERYTHING AND NOTHING IS DIR ON SPIFFS!!!! if (mountpoint != &SPIFFS) { RPC_ERR(1, (String("Selected path ") + String(fn) + String("is a directory")).c_str()); } } #endif int x = 0; file.write((uint8_t *)data + 6, m); file.close(); return 0; }
int main () { testResult_t *result = initializeTestResult(); getFS(); deleteFile("File to Delete"); deleteDir("Dir to Delete"); int newFd = openFile("NewFile"); char *text = "Here is some text."; int writeLen = writeInFile(newFd, text, strlen(text)); assert(writeLen == strlen(text), "File write return value test.", result); seekInFile(newFd, 0); char target[100]; memset(target, 0, sizeof(target)); int readLen = readInFile(newFd, target, strlen(text)); assert(readLen == strlen(text), "File write return value test.", result); deny(strcmp(target, text), "Read + write test.", result); int fd = openFile("File to Delete"); seekInFile(newFd, FILE_BLOCK_DATA_SIZE - 2); writeLen = writeInFile(newFd, text, strlen(text)); seekInFile(newFd, FILE_BLOCK_DATA_SIZE - 2); readLen = readInFile(newFd, target, strlen(text)); assert(readLen == strlen(text), "Non-contiguous allocation read+write test.", result); deny(strcmp(target, text), "Read + write test.", result); mkDir("Dir to Delete"); giveDirListing(); deleteFile("File to Delete"); mkDir("NewDir"); giveDirListing(); deleteDir("Dir to Delete"); giveDirListing(); seekInFile(newFd, 0); int i; for (i = 0; i < 150; i++) { writeInFile(newFd, text, strlen(text)); seekInFile(newFd, (i * FILE_BLOCK_DATA_SIZE) - 2); } printTestResult(result); freeTestResult(result); return 0; }
//rpc call that takes a 4 byte pointer and 2 byte len and a block of data then an fn, and writes that to a file at that pos int rpcfsdelete(void *data, unsigned int datalen, KnownClient *client, void *rbuffer, unsigned int *rlen) { *rlen = 0; fs::FS *mountpoint = getFS((char *)data + 6); //Skip the first slash if any(Assume mountpoint name is at least 2 chars) //Then get the slash after that. char *fn = strchr((char *)data + 6, '/'); if (mountpoint == 0) { RPC_ERR(3, "That device does not exist or is disconnected."); } mountpoint->remove(fn); return 0; }
int main () { testResult_t *result = initializeTestResult(); fileSystem_t *FS = getFS(); FS->superBlock->blockBitmap[0] = 0b11111111; FS->superBlock->blockBitmap[1] = 0b11111111; FS->superBlock->blockBitmap[2] = 0b00001101; assert(findEmptyBlock() == 17, "empty block find test.", result); assert(FS->activeDir->entryCount == 0, "add entry test begin", result); activeFile_t * aF = openFileInternal(FS->activeDir, "TestFile"); assert(FS->activeDir->entryCount == 1, "add entry test begin", result); directoryEntry_t dE = FS->activeDir->entries[0]; fprintf(stdout, "%s, %d, %d\n", dE.name, dE.blockType, dE.startingBlockNum); fprintf(stdout, "%s, %d\n", aF->name, aF->curContentsPtr); fileBlock_t *fB; fB = malloc(sizeof(fileBlock_t)); readBlockFromDisk(17, fB); fprintf(stdout, "%d\n", fB->blockType); assert(fB->blockType == 3, "read blockType", result); fprintf(stdout, "%s\n", fB->name); assert(findEmptyBlock() == 20, "bitmap affect test.", result); markBlockFree(17); assert(findEmptyBlock() == 17, "bitmap affect test.", result); memset(fB, 0, sizeof(fileBlock_t)); readBlockFromDisk(17, fB); fprintf(stdout, "%d\n", fB->blockType); assert(fB->blockType == 0, "free block zero set test.", result); printTestResult(result); freeTestResult(result); return 0; }
void DIV_S(unsigned long word) { //03 (03) sprintf(dis_op, "div.s\t%s, %s, %s", fpr_rn[getFD(word)], fpr_rn[getFS(word)], fpr_rn[getFT(word)]); }
void SUB_S(unsigned long word) { //01 (01) sprintf(dis_op, "sub.s\t%s, %s, %s", fpr_rn[getFD(word)], fpr_rn[getFS(word)], fpr_rn[getFT(word)]); }
void CVT_D_W(unsigned long word) { sprintf(dis_op, "cvt.d.w\t%s, %s", fpr_rn[getFD(word)],fpr_rn[getFS(word)]); }
void C_NGT_D(unsigned long word) { //63 (3F) sprintf(dis_op, "c.ngt.d\t%s, %s", fpr_rn[getFD(word)], fpr_rn[getFS(word)]); }
void C_NGE_D(unsigned long word) { //61 (3D) sprintf(dis_op, "c.nge.d\t%s, %s", fpr_rn[getFD(word)], fpr_rn[getFS(word)]); }
void C_NGL_D(unsigned long word) { //59 (3B) sprintf(dis_op, "c.ngl.d\t%s, %s", fpr_rn[getFD(word)], fpr_rn[getFS(word)]); }
void C_UN_D(unsigned long word) { //49 (31) sprintf(dis_op, "c.un.d\t%s, %s", fpr_rn[getFD(word)], fpr_rn[getFS(word)]); }
void C_F_D(unsigned long word) { //48 (30) sprintf(dis_op, "c.f.d\t%s, %s", fpr_rn[getFD(word)], fpr_rn[getFS(word)]); }
void CVT_L_D(unsigned long word) { //37 (25) sprintf(dis_op, "cvt.l.d\t%s, %s", fpr_rn[getFD(word)],fpr_rn[getFS(word)]); }
void CVT_W_D(unsigned long word) { //36 (24) sprintf(dis_op, "cvt.w.d\t%s, %s", fpr_rn[getFD(word)],fpr_rn[getFS(word)]); }
void C_NGLE_D(unsigned long word) { //57 (39) sprintf(dis_op, "c.ngle.d\t%s, %s", fpr_rn[getFD(word)], fpr_rn[getFS(word)]); }
void C_SEQ_D(unsigned long word) { //58 (3A) sprintf(dis_op, "c.deq.d\t%s, %s", fpr_rn[getFD(word)], fpr_rn[getFS(word)]); }
void C_EQ_D(unsigned long word) { //50 (32) sprintf(dis_op, "c.eq.d\t%s, %s", fpr_rn[getFD(word)], fpr_rn[getFS(word)]); }
void C_LT_D(unsigned long word) { //60 (3C) sprintf(dis_op, "c.lt.d\t%s, %s", fpr_rn[getFD(word)], fpr_rn[getFS(word)]); }
void C_UEQ_D(unsigned long word) { //51 (33) sprintf(dis_op, "c.ueq.d\t%s, %s", fpr_rn[getFD(word)], fpr_rn[getFS(word)]); }
void C_LE_D(unsigned long word) { //62 (3E) sprintf(dis_op, "c.le.d\t%s, %s", fpr_rn[getFD(word)], fpr_rn[getFS(word)]); }
void C_OLT_D(unsigned long word) { //52 (34) sprintf(dis_op, "c.olt.d\t%s, %s", fpr_rn[getFD(word)], fpr_rn[getFS(word)]); }
//COP1.L void CVT_S_L(unsigned long word) { sprintf(dis_op, "cvt.s.l\t%s, %s", fpr_rn[getFD(word)],fpr_rn[getFS(word)]); }
void C_ULT_D(unsigned long word) { //53 (35) sprintf(dis_op, "c.ult.d\t%s, %s", fpr_rn[getFD(word)], fpr_rn[getFS(word)]); }
//COP1.S void ADD_S(unsigned long word) { //00 (00) sprintf(dis_op, "add.s\t%s, %s, %s", fpr_rn[getFD(word)], fpr_rn[getFS(word)], fpr_rn[getFT(word)]); }
void C_OLE_D(unsigned long word) { //54 (36) sprintf(dis_op, "c.ole.d\t%s, %s", fpr_rn[getFD(word)], fpr_rn[getFS(word)]); }
void MUL_S(unsigned long word) { //02 (02) sprintf(dis_op, "mul.s\t%s, %s, %s", fpr_rn[getFD(word)], fpr_rn[getFS(word)], fpr_rn[getFT(word)]); }
void C_ULE_D(unsigned long word) { //55 (37) sprintf(dis_op, "c.ule.d\t%s, %s", fpr_rn[getFD(word)], fpr_rn[getFS(word)]); }
void SQRT_S(unsigned long word) { //04 (04) sprintf(dis_op, "sqrt.s\t%s, %s", fpr_rn[getFD(word)], fpr_rn[getFS(word)]); }
void C_SF_D(unsigned long word) { //56 (38) sprintf(dis_op, "c.df.d\t%s, %s", fpr_rn[getFD(word)], fpr_rn[getFS(word)]); }