C# Assignmet Help
Random speed program in CPP
This program is calculating the random speed explicitly and
implementing the concept of matrix.
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <cmath>
using namespace std;
template<typename T>
void print(T values[], int size) {
cout << "[";
for (int i = 0; i < size; i++) {
if (i > 0) cout << ", ";
cout << values[i];
}
cout << "]" << endl;
}
int main() {
// have to initialize the random seed explictly in C++.
srand(time(NULL));
FILE *input = fopen("TestSensingMatrix.txt", "r");
const int NOS = 30;
const int NOC = 2000;
const int MAX_IT = 10;
int SC[NOS][NOC];
memset(SC, 0, sizeof(SC));
// Generate the SC matrix
int row[2];
while (fscanf(input, "%d,%d", &row[0], &row[1]) == 2) {
// printf("%d,%dn", rows[0], rows[1]);
SC[row[0] - 1][row[1] - 1] = 1;
}
// s
double s[NOS];
memset(s, 0, sizeof(s));
for (int x = 0; x < NOS; x++) {
int cnt = 0;
for (int y = 0; y < NOC; y++) {
if (SC[x][y] == 1) {
cnt = cnt + 1;
}
}
s[x] = cnt * 1.0 / NOC;
}
// theta[ai]
double a[NOS];
double b[NOS];
double d = rand() % 12 / 10.0; // randint(0, 11) / 10
double Z[NOC];
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
memset(Z, 0, sizeof(Z));
for (int x = 0; x < NOS; x++) {
a[x] = s[x];
b[x] = 0.5 * s[x];
}
print(a, NOS);
print(b, NOS);
for (int itn = 0; itn < MAX_IT; itn++) { // the outer while
// Compute Z(t, j)
for (int j = 0; j < NOC; j++) {
double A = 0;
double B = 0;
// Compute Z
for (int i = 0; i < NOS; i++) {
A = A + SC[i][j] * log(a[i]) + (1-SC[i][j]) * log(1 -
a[i]);
if (b[i] <= 0) {
cout << "I am dumb and don't know how to use log
functions" << endl;
}
B = B + SC[i][j] * log(b[i]) + (1- SC[i][j]) * log(1-
b[i]);
}
A = exp(A);
B = exp(B);
Z[j] = (A * d) / ((A * d) + (B * (1 - d)));
}
// Compute new theta(t + 1)
for (int i = 0; i < NOS; i++) {
double tempa = 0;
double tempb = 0;
double tempd = 0;
double tempz = 0;
double totalz = 0;
int cnt = 0;
for (int j = 0; j < NOC; j++) {
if (SC[i][j] == 1) {
tempz = tempz + Z[j];
cnt = cnt + 1;
}
totalz = totalz + Z[j];
}
a[i] = tempz / totalz;
b[i] = (cnt - tempz) / (NOC - totalz);
if (b[i] < 0) {
cout << i << " is the problem step" << endl;
break;
}
d = totalz / NOC;
}
}
// end of while
cout << d << endl;
print (a, NOS);
print (b, NOS);
FILE *groundtruth = fopen("TestGroundTruth.txt", "r");
int gt[NOC];
memset(gt, 0, sizeof(gt));
while (fscanf(input, "%d,%d", &row[0], &row[1]) == 2) {
// printf("%d,%dn", rows[0], rows[1]);
gt[row[0] - 1] = row[1];
}
int out[NOC];
memset(out, 0, sizeof(out));
FILE *output = fopen("output.txt", "w");
for (int j = 0; j < NOC; j++) {
if (Z[j] >= 0.5) {
out[j] = 1;
}
}
double t[NOS];
memset(t, 0, sizeof(t));
for (int i = 0; i < NOS; i++) {
t[i] = a[i] / (a[i] + b[i]);
cout << t[i] << endl;
}
for (int j = 0; j < NOC; j++) {
fprintf(output, "%d, %dn", j+1, out[j]);
}
fclose(input);
}

More Related Content

PDF
Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"
DOCX
C programs
PDF
Timur Shemsedinov "Пишу на колбеках, а что... (Асинхронное программирование)"
PDF
Data structure programs in c++
KEY
Grand centraldispatch
PDF
Rubinius @ RubyAndRails2010
PDF
Brief intro to clojure
PDF
Single qubit-gates operations
Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"
C programs
Timur Shemsedinov "Пишу на колбеках, а что... (Асинхронное программирование)"
Data structure programs in c++
Grand centraldispatch
Rubinius @ RubyAndRails2010
Brief intro to clojure
Single qubit-gates operations

What's hot (20)

PDF
CUDA First Programs: Computer Architecture CSE448 : UAA Alaska : Notes
PDF
OOP 2012 - Hint: Dynamic allocation in c++
PPTX
Better performance through Superscalarity
PDF
Gems of GameplayKit. UA Mobile 2017.
PDF
What they don't tell you about JavaScript
PDF
Multi qubit entanglement
PDF
オープンデータを使ったモバイルアプリ開発(応用編)
PPT
Full-Stack JavaScript with Node.js
PDF
Understanding the nodejs event loop
PDF
An Introduction to JavaScript: Week 5
PDF
Zone.js 2017
DOC
Program(Output)
KEY
Cocos2d実践編 1.0.0rc
PDF
Microsoft Word Hw#1
PDF
OpenGL L07-Skybox and Terrian
DOC
PDF
20151224-games
PDF
RxJS 5 in Depth
PDF
C++ TUTORIAL 10
CUDA First Programs: Computer Architecture CSE448 : UAA Alaska : Notes
OOP 2012 - Hint: Dynamic allocation in c++
Better performance through Superscalarity
Gems of GameplayKit. UA Mobile 2017.
What they don't tell you about JavaScript
Multi qubit entanglement
オープンデータを使ったモバイルアプリ開発(応用編)
Full-Stack JavaScript with Node.js
Understanding the nodejs event loop
An Introduction to JavaScript: Week 5
Zone.js 2017
Program(Output)
Cocos2d実践編 1.0.0rc
Microsoft Word Hw#1
OpenGL L07-Skybox and Terrian
20151224-games
RxJS 5 in Depth
C++ TUTORIAL 10
Ad

Similar to C# Assignmet Help (20)

PDF
C++ normal assignments by maharshi_jd.pdf
DOCX
code (1) thông tin nhập môn cntt hdsd.docx
PPTX
Федор Поляков (Looksery) “Face Tracking на мобильных устройствах в режиме реа...
PDF
2014 computer science_question_paper
PDF
Asssignment2
PPT
Lập trình C
PDF
Write Python for Speed
PDF
Tools.cpp
DOCX
Assignement of programming & problem solving u.s ass.(1)
DOCX
TXT
Snake.c
PDF
oodp elab.pdf
DOCX
ماترێکس به‌ کوردی ئارام
PDF
pattern-printing-in-c.pdf
DOCX
DOCX
codings related to avr micro controller
PDF
COA_remaining_lab_works_077BCT033.pdf
RTF
project3
PDF
Pattern printing-in-c(Jaydip Kikani)
DOCX
Os lab file c programs
C++ normal assignments by maharshi_jd.pdf
code (1) thông tin nhập môn cntt hdsd.docx
Федор Поляков (Looksery) “Face Tracking на мобильных устройствах в режиме реа...
2014 computer science_question_paper
Asssignment2
Lập trình C
Write Python for Speed
Tools.cpp
Assignement of programming & problem solving u.s ass.(1)
Snake.c
oodp elab.pdf
ماترێکس به‌ کوردی ئارام
pattern-printing-in-c.pdf
codings related to avr micro controller
COA_remaining_lab_works_077BCT033.pdf
project3
Pattern printing-in-c(Jaydip Kikani)
Os lab file c programs
Ad

More from Programming Homework Help (8)

PDF
Java Assignment Help
PDF
C# Assignmet Help
PDF
Family tree in java
PDF
Binary tree in java
PDF
Bank account in java
PDF
Mouse and Cat Game In C++
PDF
Word games in c
PDF
Card Games in C++
Java Assignment Help
C# Assignmet Help
Family tree in java
Binary tree in java
Bank account in java
Mouse and Cat Game In C++
Word games in c
Card Games in C++

Recently uploaded (20)

PDF
AI-driven educational solutions for real-life interventions in the Philippine...
PDF
LIFE & LIVING TRILOGY- PART (1) WHO ARE WE.pdf
PDF
Complications of Minimal Access-Surgery.pdf
PDF
English Textual Question & Ans (12th Class).pdf
PDF
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 2).pdf
PDF
My India Quiz Book_20210205121199924.pdf
PDF
Journal of Dental Science - UDMY (2021).pdf
PDF
semiconductor packaging in vlsi design fab
PDF
HVAC Specification 2024 according to central public works department
PDF
CISA (Certified Information Systems Auditor) Domain-Wise Summary.pdf
PPTX
Introduction to pro and eukaryotes and differences.pptx
PDF
Τίμαιος είναι φιλοσοφικός διάλογος του Πλάτωνα
PDF
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
PDF
Race Reva University – Shaping Future Leaders in Artificial Intelligence
PPTX
B.Sc. DS Unit 2 Software Engineering.pptx
PPTX
ELIAS-SEZIURE AND EPilepsy semmioan session.pptx
PDF
Uderstanding digital marketing and marketing stratergie for engaging the digi...
PDF
MBA _Common_ 2nd year Syllabus _2021-22_.pdf
PPTX
What’s under the hood: Parsing standardized learning content for AI
PDF
advance database management system book.pdf
AI-driven educational solutions for real-life interventions in the Philippine...
LIFE & LIVING TRILOGY- PART (1) WHO ARE WE.pdf
Complications of Minimal Access-Surgery.pdf
English Textual Question & Ans (12th Class).pdf
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 2).pdf
My India Quiz Book_20210205121199924.pdf
Journal of Dental Science - UDMY (2021).pdf
semiconductor packaging in vlsi design fab
HVAC Specification 2024 according to central public works department
CISA (Certified Information Systems Auditor) Domain-Wise Summary.pdf
Introduction to pro and eukaryotes and differences.pptx
Τίμαιος είναι φιλοσοφικός διάλογος του Πλάτωνα
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
Race Reva University – Shaping Future Leaders in Artificial Intelligence
B.Sc. DS Unit 2 Software Engineering.pptx
ELIAS-SEZIURE AND EPilepsy semmioan session.pptx
Uderstanding digital marketing and marketing stratergie for engaging the digi...
MBA _Common_ 2nd year Syllabus _2021-22_.pdf
What’s under the hood: Parsing standardized learning content for AI
advance database management system book.pdf

C# Assignmet Help

  • 2. Random speed program in CPP This program is calculating the random speed explicitly and implementing the concept of matrix. #include <iostream> #include <cstdio> #include <cstdlib> #include <ctime> #include <cmath> using namespace std; template<typename T> void print(T values[], int size) { cout << "["; for (int i = 0; i < size; i++) { if (i > 0) cout << ", "; cout << values[i]; } cout << "]" << endl; } int main() { // have to initialize the random seed explictly in C++. srand(time(NULL)); FILE *input = fopen("TestSensingMatrix.txt", "r"); const int NOS = 30; const int NOC = 2000; const int MAX_IT = 10; int SC[NOS][NOC]; memset(SC, 0, sizeof(SC)); // Generate the SC matrix int row[2]; while (fscanf(input, "%d,%d", &row[0], &row[1]) == 2) { // printf("%d,%dn", rows[0], rows[1]); SC[row[0] - 1][row[1] - 1] = 1; } // s double s[NOS]; memset(s, 0, sizeof(s)); for (int x = 0; x < NOS; x++) { int cnt = 0; for (int y = 0; y < NOC; y++) { if (SC[x][y] == 1) {
  • 3. cnt = cnt + 1; } } s[x] = cnt * 1.0 / NOC; } // theta[ai] double a[NOS]; double b[NOS]; double d = rand() % 12 / 10.0; // randint(0, 11) / 10 double Z[NOC]; memset(a, 0, sizeof(a)); memset(b, 0, sizeof(b)); memset(Z, 0, sizeof(Z)); for (int x = 0; x < NOS; x++) { a[x] = s[x]; b[x] = 0.5 * s[x]; } print(a, NOS); print(b, NOS); for (int itn = 0; itn < MAX_IT; itn++) { // the outer while // Compute Z(t, j) for (int j = 0; j < NOC; j++) { double A = 0; double B = 0; // Compute Z for (int i = 0; i < NOS; i++) { A = A + SC[i][j] * log(a[i]) + (1-SC[i][j]) * log(1 - a[i]); if (b[i] <= 0) { cout << "I am dumb and don't know how to use log functions" << endl; } B = B + SC[i][j] * log(b[i]) + (1- SC[i][j]) * log(1- b[i]); } A = exp(A); B = exp(B); Z[j] = (A * d) / ((A * d) + (B * (1 - d))); } // Compute new theta(t + 1) for (int i = 0; i < NOS; i++) { double tempa = 0; double tempb = 0; double tempd = 0; double tempz = 0;
  • 4. double totalz = 0; int cnt = 0; for (int j = 0; j < NOC; j++) { if (SC[i][j] == 1) { tempz = tempz + Z[j]; cnt = cnt + 1; } totalz = totalz + Z[j]; } a[i] = tempz / totalz; b[i] = (cnt - tempz) / (NOC - totalz); if (b[i] < 0) { cout << i << " is the problem step" << endl; break; } d = totalz / NOC; } } // end of while cout << d << endl; print (a, NOS); print (b, NOS); FILE *groundtruth = fopen("TestGroundTruth.txt", "r"); int gt[NOC]; memset(gt, 0, sizeof(gt)); while (fscanf(input, "%d,%d", &row[0], &row[1]) == 2) { // printf("%d,%dn", rows[0], rows[1]); gt[row[0] - 1] = row[1]; } int out[NOC]; memset(out, 0, sizeof(out)); FILE *output = fopen("output.txt", "w"); for (int j = 0; j < NOC; j++) { if (Z[j] >= 0.5) { out[j] = 1; } } double t[NOS]; memset(t, 0, sizeof(t)); for (int i = 0; i < NOS; i++) { t[i] = a[i] / (a[i] + b[i]); cout << t[i] << endl; } for (int j = 0; j < NOC; j++) {
  • 5. fprintf(output, "%d, %dn", j+1, out[j]); } fclose(input); }