This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
You are given a 2D matrix, a, of dimension MxN and a positive integer R. You have to rotate the matrix R times and print the resultant matrix. Rotation should be in anti-clockwise direction. | |
Rotation of a 4x5 matrix is represented by the following figure. Note that in one rotation, you have to shift elements by one step only (refer sample tests for more clarity). | |
Matrix-rotation | |
It is guaranteed that the minimum of M and N will be even. | |
Input | |
First line contains three space separated integers, M, N and R, where M is the number of rows, N is number of columns in matrix, and R is the number of times the matrix has to be rotated. | |
Then M lines follow, where each line contains N space separated positive integers. These M lines represent the matrix. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <math.h> | |
#include <stdio.h> | |
#include <string.h> | |
#include <stdlib.h> | |
#include <assert.h> | |
#include <limits.h> | |
#include <stdbool.h> | |
int main() | |
{ | |
int a0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main() | |
{ | |
int a = 10, b = 0, c = 10; | |
char* str = "TFy!QJu ROo TNn(ROo)SLq SLq ULo+UHs UJq " |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* package codechef; // don't place package name! */ | |
import java.util.Scanner; | |
import java.util.Stack; | |
/* Name of the class has to be "Main" only if the class is public. */ | |
class Codechef | |
{ | |
public static void main (String[] args) throws java.lang.Exception | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(psych) | |
roomtrain = read.table('datatraining.txt',header = TRUE,sep = ',',stringsAsFactors = FALSE) | |
roomtest1= read.table('datatest.txt',header = TRUE,sep = ',',stringsAsFactors = FALSE) | |
roomtest2= read.table('datatest2.txt',header = TRUE,sep = ',',stringsAsFactors = FALSE) | |
#Combine all three | |
room = rbind(roomtrain,roomtest1,roomtest2) | |
#Remove date and convert occupancy to factor | |
room = room[-1] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Feature Scaling & Mean Normalization | |
#This function is EXACTLY equivalent to the scale() function in R | |
//Remember to exclude the last column of the data, we should not normalize what we predict. | |
room_n = scale(room[1:5]) | |
//Or all this function | |
normalize = function(x) | |
{ | |
return ((x - mean(x))/sd(x)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Install the package, if you havn't already done so. | |
install.packages('psych') | |
#Randomply sample the data into two parts with replacement and probability | |
ind = sample(2,nrow(room_n),replace = TRUE,prob = c(0.8,0.2)) | |
train = room_n[ind==1,] | |
test = room_n[ind==2,] | |
#Predictors | |
X = as.matrix(train[,-6]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
model = glm(Occupancy~.,train,family= binomial(link = "logit") | |
pred = predict(model,test[,-6]) | |
#All values with probability less than 0.7 are considered occupied. | |
pred[pred>=0.7] = 1 | |
pred[pred<0.7] = 0 | |
pred = factor(pred) | |
plot(pred) | |
#Calculate R-sqaured value |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sigmoid = function(z) | |
{ | |
return(1/(1 + exp(-z))) | |
} | |
cost = function(T) | |
{ | |
h = sigmoid(X%*%T) | |
m = nrow(X) | |
J = (1/m) * sum((-Y*log(h)) - (1-Y)*log(1-h)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Install the pakages if you haven't already done so | |
install.packages('nnet') | |
nnet = neuralnet(Occupancy ~ Temperature + Humidity + Light + CO2 + HumidityRatio,data=train,linear.output = FALSE,hidden = c(3,2)) | |
#Predicted values | |
pred = compute(nnet,test[,-6]) | |
pred = pred$net.result | |
#From the graph, for all predictions greater than 0.7 1 else 0 |
OlderNewer