Monday, July 29, 2013

Anomaly Detection using Oracle R Enterprise (ORE) | SVM for Anomaly Detection

R is an open source scripting language and environment for statistical computing, data analysis & graphics.R provides an integrated suite of software facilities for data manipulation, calculation and graphical display- it's an integrated environment. Around 2 million users in the world are widely using R especially by corporate analysts & data scientists.

Anomaly/Outlier detection has wide applications. It can be used in fraud detection, for example, by detecting unusual usage of credit cards or telecommunication services. In addition, it is useful in customized marketing for identifying the spending behavior of customers with extremely low or extremely high incomes, or in medical analysis for finding unusual responses to various medical treatments.

Wednesday, June 19, 2013

Random Numbers Generation & Chi-Squared Test for their Uniformity in C++

Continuous uniformly distributed random numbers means the set of random numbers where probability of any number in any integral within a certain range of values is proportional to the ratio of the interval size to the range. The generated random numbers require to be independent & uniform in distribution. There are many different methods to generate the random numbers. 
They are: 
  • Random numbers from table. 
  • From hardwired device. 
  • Using pseudo Number generation. 

In linear congruential method, we use one initial number (rcalled seed) and few constants. Using the seed and the formula, 
                       ri+1 = (ri ×a + b) (modulo m) 

Wednesday, June 12, 2013

Determinant Calculation of Nth Order Square Matrix| Cramer's Rule Implementation in C

Determinant calculation of a square matrix is widely used in solving many applied Mathematics problems. Some of them are while solving a set of linear equations using Cramer's rule (iff they have unique solutions), calculation of inverse matrix, Eigen values/ Eigen vectors problem and so on.

The determinant of a square matrix A∈Rn×n is the real number det(A) defined as follows:

det(A) = SUMperm [sign(ν1,ν2,...,νn)a1ν1a2ν2...anνn]

Saturday, June 8, 2013

Autodesk AutoCAD 2010 is Already Installed| Problem Re-installing AutoCAD 2010| Solution

After facing some of the troubles and uninstalling the AutoDesk AutoCAD 2010, when you try to re-install the AutoCAD, you may often have to go through this problem. This is actually the problem which remained after  uninstalling the AutoCAD. Before trying to provide the solution, I would like to suggest to clean up your computer system using some clean up tools such as Windows Installer Clean UP Utility, CCleaner etc. after you uninstall a software.

CD/DVD Drive not Found Problem| CD/DVD Drive is not Detected Problem| Windows 7 Problem Solution

In windows 7, if you are facing the optical drives not detected/ not found problem even if it is visible in BIOS and using the standard driver, then you can try out the following options. The standard solution that worked in my desktop is as follows:

  • Press Win key and type regedit.exe, a new window- Registry Editor will open
  • After that, navigate to the following path from the left pane:

Friday, June 7, 2013

Huffman Algorithm Implementation in C| Huffman Encoding| Huffman Algorithm Example

Huffman Algorithm is an encoding technique for symbols where most frequently occuring symbols are represented with short length bit strings and least frequently occuring symbols are represented with long bit strings.

This algorithm is widely used as the fundamental encoding algorithm in compressing audio and image files.

Wednesday, May 29, 2013

Solution of Ordinary Differential Equation using Runge-Kutta Method | RK4 method for ODE Solution in C

In numerical analysis, the Runge–Kutta methods are an important family of implicit and explicit iterative methods for the approximation of solutions of ordinary differential equations. These techniques were developed around 1900 by the German mathematicians C. Runge and M. W. Kutta.

There are many variants of the Runge-Kutta method, but the most widely used one is the following known as RK-4 method: 
y' = f(x,y) 
y(xn) = yn 
we compute in turn 
k1 = hf(xn,yn) 
k 2 = hf (xn+h/2,yn+k1/2)
k3 = hf (xn+h/2,yn+k2/2)
k4 = hf(xn + h, yn + k3) 
yn+1 = yn + (k1 + 2*k2 + 2*k3 + k4 )/6

This algorithm can be implemented  using the following source code in C:

Friday, May 24, 2013

Gauss Jordan Method Implementation with C Source Code

In linear algebra, Gaussian Jordan method is an algorithm for solving systems of linear equations. It is usually understood as a sequence of operations performed on the associated matrix of coefficients. This method can also be used to find the rank of a matrix, to calculate the determinant of a matrix, and to calculate the inverse of an invertible square matrix.

We can implement this method in C using the following source code:
//Implementation of Gauss Jordan Method, @author: +Jivan Nepali, @URL: codeplustech
 #define Max 10  
 int main()  
   float a[Max][Max+1],t,det=1;  
   int i,j,k,N;  
   printf("Enter the number of unknowwns : ");  

Thursday, May 23, 2013

Modeling & Simulation of Chemical Reaction | Continuous System Simulation | C++ Implementation

Chemical reactions exhibit dynamic equilibrium, which means that a combination reaction is also accomplished by the reverse process of decomposition reaction. At the steady state the rates of the forward and the backward reaction is same.

In addition to the forward reaction where Ch1 and Ch2 react to produce Ch3, there may also be backward reaction, where by, Ch3 decomposes back into Ch1 and Ch2. Let the rate of formation of Ch3 be proportional to the product of the amounts Ch1 and Ch2 present in the mixture and let the rate of decomposition of Ch3 be proportional to its amount in the mixture. 
Let us consider C1, C2  and C3 Amount of Ch1, Ch2 and Ch3 at any instant of time t, the rate of increase of C1, C2& C3 are given by the following differential equations:

dC1/dt = K1C3– K1C1C2
dC2/dt = K2C3– K1C1C2

Where K1and K2 are constants.

Tuesday, May 21, 2013

Preventing Windows 8 from Automatically Launching Browser on Network Connection | Solutions

With the newer version of Microsoft's Windows Operating System- Windows 8, its users are experiencing newer and more advanced features than the older versions. But, at the same time they may have been facing with some of the strange troubles.

One such issue is that Windows 8 automatically launches its default browser upon the the internet connection. To some users it may be helpful as they need not to open the browser and especially for users in a LAN provided by some institutions such as University, it may be the sign of avialability of the internet connection. But, for most of the users such as those posting in Microsoft's Community Page, it may be really problematic. 

"Windows is launching the following link in Internet Explorer:

which leads to Bing. When I enable my internet connection Bing will popup from time to time. When I disable Internet Explorer via the Windows Features, the link will open in Mozilla Firefox."

So, the steps that I followed for solving this issue are given:

Saturday, May 18, 2013

Newton-Raphson Method in C with source codes

Newton-Raphson method is a method for finding successively better roots (zeros) of a real valued function
x: f(x) = 0.

The algorithm can be implemented in C as follows:

#define h pow(10,-6)
#define error pow(10,-6)
double f(double x)
double df(double x)
 return 2*x;

Implementation of Warshall's Algorithm in C++ with Source Codes

Warshall's algorithm is used to find the transitive closure of a graph. It's one of the efficient method to compute closure path that can be produced. Transitive closure is an important application in graph theory in computer science.
The following provides the source codes for implementing the Warshall's algorithm:



using namespace std;
const int num_nodes =10;

int main()
    //..............................................................VARIABLE DECLARATION
    int num_nodes,k,n;
    char i,j,res,c;
    int adj[10][10],path[10][10];

C Source Code for Dijkstra's Shortest Path Algorithm

Dijkstra's Shortest Path Algorithm is the popular algorithm for finding shortest/optimal path in compute science due to its widespread application in different branches- computer networks, distributed systems, signal processing etc.

I've implemented the algorithm for finding the minimum distance between any two nodes:

///......................................SHORTEST PATH ALGORITHM << Dijkstra Algorithm >>......................

#define MAX_NODES 10
#define INFINITY 1000
#define MEMBER 1
#define NON_MEMBER 0

struct arc{
    int adj;
    int weight;
int main(){

    int i,j,k,weight[MAX_NODES][MAX_NODES],num_nodes,source,dest,precede[MAX_NODES];
    int distance[MAX_NODES],permanent_nodes_set[MAX_NODES];
    int current,current_distance,n;
    int smalldist,newdist;
    char s,d,node;

    printf("\t\t\t\tSHORTEST PATH ALGORITHM << Dijkstra Algorithm >>");
    printf("\n\n\t\t\tAssign 1000 as INFINITY for non-adjacent nodes !!\n\n");
    printf("\nEnter the number of nodes in the GRAPH :");

                printf("\nEnter weight for arc[%c][%c] :",65+i,65+j);
                weight[j][i] =weight[i][j];
                weight[i][i] =INFINITY;

    printf("\nEnter the source _node :");scanf(" %c",&s);
    source =(int)(s-97);
    printf("\nEnter the destination_node :");scanf(" %c",&d);
    dest = (int)(d-97);

    printf("\n\t\t\tThe shortest path is :>>\n\n\t\t\t");
        permanent_nodes_set[i] =NON_MEMBER;
        distance[i] =INFINITY;
        smalldist =INFINITY;
        current_distance =distance[current];
            if(permanent_nodes_set[i] ==NON_MEMBER)
            newdist =current_distance+weight[current][i];
                    printf(" %c ->",65+current);
                node =65+current;

                smalldist =distance[i];
                k =i;


         current =k;
         permanent_nodes_set[current] =MEMBER;


        printf(" %c ->",65+dest);
        printf("\n\n\t\t\tThe shortest distance = %d\n",distance[dest]);

        return 0;

Priority Queue Implementation: C source codes

A priority queue is data structure in which intrinsic ordering of the elements does determine the results of its basic operations. These are of two types- ascending (e.g. queue) and descending (e.g. stack).
The following source code implements ascending type priority queue in C:

// Ascending Priority Queue Implementation in C

    const int MAX=5;

    class pqueue
          int front,rear;
          struct data
           int val,p,o;

Merge Sort Algorithm with C source Codes

Here, I've presented the merge sort algorithm as the straight merge sort. The basic idea is to break the file into n subfiles of size 1 and merge adjacent disjoint pairs of files and repeating the process until we've single file remaining of size n.
 The C Source codes is as follows:

// Merge sort implementation in C

void getdata(int arr[],int n)
 int i;
  printf("\nEnter the data:");

C Source Codes for Implementing Linked List

The linked list can be implemented using the pointer structure in C so that we can

  • add an element
  • delete an element
  • search for an element
  • concatenate two linked list
  • Invert a linked list
  • Display elements in the list

//Program to demonstrate linked list operations

# include<stdio.h>
# include<conio.h>
# include "malloc.h"
struct node
int data;
struct node *link;

Implement Infix to postfix conversion using Stack C source codes

We can implement a valid infix expression to a valid postfix expression using stacks in c as shown:


#define MAX 20

char stack[MAX];
int istack[MAX];
int top = -1;
char pop();
void push(char item);

Code Generator in C

The following code generates the code itself. The code seems to be simple but it's little bit tricky and is FAQ for programmers in an interview.

char *s="#include%c#include%cchar *s=%c%s%c;%cvoid main()%c{%cclrscr();-%cprintf(s,10,10,34,s,34,10,10,10,10,10,10);%cgetch();%c}";
void main(){

Binary Tree Implementation in C with Tree Traversals

We can implement the binary tree using C so that we can add a node, delete a node, and can perform different tree traversals:
 1. Preorder tree traversal
 2. Inorder tree traversal
 3. Post order tree traversal

/// ..............................................BINARY TREE OPERATIONS AND TREE TRAVERSALS


///.................................................................DYNAMIC STRUCTURE FOR BINARY TREE

struct tree
     int info;
     struct tree *left_subtree;
     struct tree *right_subtree;

Saturday, May 11, 2013

Time & Space Complexity of Basic K-means Algorithm

The basic k-means clustering algorithm is a simple algorithm that separates the given data space into different clusters based on centroids calculation using some proximity function. Using this algorithm, we first choose the k- points as initial centroids and then each point is assigned to a cluster with the closest centroid. The algorithm is formally described as follows:
Input: A data set D containing m objects (points) with n attributes in an              Euclidean space
Output: Partitioning of m objects into k-clusters C1, C2, C3, …, Cki.e. Ci  D and Ci ∩ Cj = ᶲ  (for 1 ≤ i, j ≤ k)

DBSCAN Algorithm Implementation in MATLAB

Density Based Spatial Clustering of Applications with Noise (DBSCAN) Algorithm locates regions of high density that are separated from one another by regions of low density. DBSCAN is a center based approach to clustering in which density is estimated for a particular point in the data set by counting the number of points within the specified radius, ɛ, of that point.
The center based approach to density allows us to classify a point as one of the three:

     Core points: These points are in the interior of the dense region
   Border points:These points are not the core points, but fall within the neighborhood of the core points
   Noise points: A noise point is a point that is neither a core point nor a border point.
            The formal definition of DBSCAN algorithm is illustrated below: