Monday, October 31, 2005

Memoization Rocks

// Testing.cpp : Defines the entry point for the console application.
//

#include "iostream"

using namespace std;

int results[50];


long memoized_fibonacci_recurs(int results[],int n) {

long val = 0;
if (results[n] != -1)
return results[n];

if (n == 1)

val = 1;

else if (n == 2)

val = 1;

else {

val = memoized_fibonacci_recurs(results,n - 2);
val = val + memoized_fibonacci_recurs(results,n - 1);
}

results[n] = val;

return val;

}

long fib(int num)
{
if ( num == 0 )
return 0;
if ( num == 1)
return 1;
else
return (fib(num-1) + fib(num-2));
}


long memoized_fibonacci(int n) {

for(int i = 0; i < 50; i++)

results[i] = -1; // -1 means undefined

return memoized_fibonacci_recurs(results,n);

}




int main(int argc, char*argv[])
{
long num = fib(40);

long num1 = memoized_fibonacci(40);

cout << "Computed Value is:" << num << endl;
cout << "Memoized Computed Value is:" << num1 << endl;
}

Wednesday, October 26, 2005

Maximum Likelihood

Let X=( $ X_1,\ldots,X_n$) be a random vector and

$\displaystyle \lbrace f_{\mathbf{X}}(\boldsymbol{x}\mid\boldsymbol{\theta}) : \boldsymbol{\theta} \in \Theta \rbrace$
a statistical model parametrized by $ \boldsymbol{\theta}=(\theta_1,\ldots,\theta_k)$, the parameter vector in the parameter space $ \Theta$. The likelihood function is a map $ L: \Theta \rightarrow [0,1]\subset \mathbb{R}$ given by
$\displaystyle L(\boldsymbol{\theta}\mid\boldsymbol{x}) = f_{\mathbf{X}}(\boldsymbol{x}\mid\boldsymbol{\theta}).$
In other words, the likelikhood function is functionally the same in form as a probability density function. However, the emphasis is changed from the $ \boldsymbol{x}$ to the $ \boldsymbol{\theta}$. The pdf is a function of the $ x$'s while holding the parameters $ \theta$'s constant, $ L$ is a function of the parameters $ \theta$'s, while holding the $ x$'s constant.

When there is no confusion, $ L(\boldsymbol{\theta}\mid\boldsymbol{x})$ is abbreviated to be $ L(\boldsymbol{\theta})$.

The parameter vector $ \hat{\boldsymbol{\theta}}$ such that $ L(\hat{\boldsymbol{\theta}})\geq L(\boldsymbol{\theta})$ for all $ \boldsymbol{\theta}\in\Theta$ is called a maximum likelihood estimate, or MLE, of $ \boldsymbol{\theta}$.

Monday, October 24, 2005

Standard Deviation

Suppose we are given a population x1, ..., xN of values (which are real numbers). The arithmetic mean of this population is defined as

http://en.wikipedia.org/wiki/Standard_deviation For formulaes

Monday, October 17, 2005

Probability Distribution function

Random variables: Are the real valued functions defined on the sample space i.e they map the outcomes of an experiment from a non-real outcome to real numbers outcome.

Analogy: For e.g while tossing a dice we are not interested in the actual outcomes but are interested in the functions of the outcome

A random variable that can take at most a countable number of possible values is said to be discrete. For discrete random variable we define probability mass function

Picked from lecture notes :) for my reference ( thanks to whoever did it)

Cumulative Distributive function
--------------------------------------
What is the probability that x is less than or equal to x0?
The probability that x < x="-" infinity="" integral="" x0="" dx="">

This integral yields the area under the curve between x = -∞ and x = x0
and is called the cumulative density function or cdf denoted by ‘g’.


•Variance – measure of the deviation from the mean for points in one dimension e.g. heights
•
•Covariance as a measure of how much each of the dimensions vary from the mean with respect to each other.

•
•Covariance is measured between 2 dimensions to see if there is a relationship between the 2 dimensions e.g. number of hours studied & marks obtained.

•The covariance between one dimension and itself is the variance

Covariance Properties
---------------------------------

•Exact value is not as important as it’s sign.
•A positive value of covariance indicates both dimensions increase or decrease together e.g. as the number of hours studied increases, the marks in that subject increase.

•A negative value indicates while one increases the other decreases, or vice-versa e.g. active social life at RIT vs performance in CS dept.

•If covariance is zero: the two dimensions are independent of each other e.g. heights of students vs the marks obtained in a subject

Covariance calculations are used to find relationships between dimensions in high dimensional data sets (usually greater than 3) where visualization is difficult

variance (X) = Σi=1n(Xi – X) (Xi – X)
(n -1)
covariance (X,Y) = Σi=1n(Xi – X) (Yi – Y)
(n -1)

•the mass (probability) of a small section of wire is the mass per unit length (density) times it length of section (bin width) under consideration.




Analysis Server Database Backups

The backup extensions for analysis server are .abf, you connect to the analysis server database and right click on it to restore a database with .abf extension to restore the database.

Dunno what i wrote :)

-Kalyan

Monday, September 26, 2005

Mantis Bug Tracking System

So I installed the Bug tracking system,

Mantis and this seems pretty interesting bugtracking system with minimal overheads of installation so that is what I thought.

Some of the issues that I ran into
1. Bug database installed into other system ( so I had to add this user to the database giving this user access to this database , like
GRANT ALL PRIVILEGES ON .* TO 'monty'@'machinename'
IDENTIFIED BY 'some_pass' WITH GRANT OPTION;

2. PHP captcha problem , so had to comment that part of code,
tried playing around with the captcha code but seems to fail on all occassions.


-Kalyan

Wednesday, September 21, 2005

Interfaces in C#

I wrote this small template in C# for using interfaces

interface Itest
{
void show();
}

class cl:Itest
{
void show()
{

}

}

Throws an error saying that the show must be either public, static. Trying to find out what is the default scope of the members in C#.

Assemblies decide the scope of the class not namespace, sounds funny as to why anyone would do that as to decide the scope based on the assembly and not on the namespace.

Investigating further
-Kalyan

Friday, September 09, 2005

logarithm function definition

y = bx
logb(y) = x

from putplemath


Big Oh notation

Sometimes, it is very necessary to compare the order of some common used functions including the following:

1 logn n nlogn n2 2n n! nn

Now, we can use what we've learned above about the concept of big-Oh and the calculation methods to calculate the order of these functions. The result shows that each function in the above list is big-oh of the functions following them. The figure below displays the graphs of these funcions, using a scale for the values of the functions that doubles for each successive marking on the graph.

Wednesday, August 24, 2005

Recursion

Recursion
------------

1. Binary Search
2. Permutation
3. Combination
4. Telephone words


-Kalyan

Friday, August 19, 2005

Condor Project

Site Reference:
http://www.cs.wisc.edu/condor/

High throughput computing
- Develop
-Implement
-Deploy

Specialized workload management system for computer intersive jobs.
Condor provides
- a job queuing system
- scheduling policy
- priority scheme
- resource monitoring
- resource management

Users submit their serial or parallel jobs to Condor, Condor places them into a queue, chooses when and where to run the jobs based upon a policy, carefully monitors their progress, and ultimately informs the user upon completion.

Similar to batch queueing system. Condor can be used to seamlessly combine all of an organization's computational power into one resource.

Condor provides high throughput
- Available resources more efficient. (That is resource usage more efficient)
- Expands the resources availabe to users.

Thursday, August 18, 2005

What is a Random Variable?

Random Variable

The outcome of an experiment need not be a number, for example, the outcome when a coin is tossed can be 'heads' or 'tails'. However, we often want to represent outcomes as numbers. A random variable is a function that associates a unique numerical value with every outcome of an experiment. The value of the random variable will vary from trial to trial as the experiment is repeated.

There are two types of random variable - discrete and continuous.

A random variable has either an associated probability distribution (discrete random variable) or probability density function (continuous random variable).

Examples

  1. A coin is tossed ten times. The random variable X is the number of tails that are noted. X can only take the values 0, 1, ..., 10, so X is a discrete random variable.
  2. A light bulb is burned until it burns out. The random variable Y is its lifetime in hours. Y can take any positive real value, so Y is a continuous random variable.
Probability Distribution

The probability distribution of a discrete random variable is a list of probabilities associated with each of its possible values. It is also sometimes called the probability function or the probability mass function.

More formally, the probability distribution of a discrete random variable X is a function which gives the probability p(xi) that the random variable equals xi, for each value xi: p(xi) = P(X=xi)

It satisfies the following conditions:

  1. 0 <= p(xi) <= 1
  2. sum of all p(xi) is 1

Cumulative Distribution Function

All random variables (discrete and continuous) have a cumulative distribution function. It is a function giving the probability that the random variable X is less than or equal to x, for every value x.

Formally, the cumulative distribution function F(x) is defined to be: F(x) = P(X<=x)
for -infinity < x < infinity

For a discrete random variable, the cumulative distribution function is found by summing up the probabilities as in the example below.

For a continuous random variable, the cumulative distribution function is the integral of its probability density function.

Example
Discrete case : Suppose a random variable X has the following probability distribution p(xi):
xi
0 1 2 3 4 5
p(xi)
1/32 5/32 10/32 10/32 5/32 1/32
This is actually a binomial distribution: Bi(5, 0.5) or B(5, 0.5). The cumulative distribution function F(x) is then:
xi
0 1 2 3 4 5
F(xi)
1/32 6/32 16/32 26/32 31/32 32/32

F(x) does not change at intermediate values. For example:
F(1.3) = F(1) = 6/32
F(2.86) = F(2) = 16/32

Tuesday, August 16, 2005

SQLPLUS formatting

set recsep off
set linesize 100
set newpage 0
set pagesize 999
column famname format a15
column rufname format a10
column gebdat format a10
select famname, rufname, gebdat, om from e01e001 where...
FAMNAME        RUFNAME    GEBDAT             OM
-------------- ---------- ---------- ----------
Lippmann Richard 09.07.1966 12
Meier Luise 01.01.1834 13

-Kalyan

Oracle Tablespace usage query

select tablespace_name, owner, sum(bytes)/1024/1024 Mb
from dba_segments
where owner not in ('SYS','SYSTEM')
group by tablespace_name, owner
order by 3

http://www.blacksheepnetworks.com/security/resources/www.think-forward.com/sql/du.htm

A good reference for sqlplus

http://www.psoug.org/reference/sqlplus.html

-Kalyan

Monday, August 15, 2005

Market Basket Data set

http://fimi.cs.helsinki.fi/data/retail.dat.gz

-Kalyan

THE X Window System

http://www.cs.washington.edu/lab/sw/uwcsexintro.html
Wikipedia site are good references for this


-Kalyan

Wednesday, August 10, 2005

Perl Tricks

The code:


BEGIN{unshift @INC, "/tmp"}

can be replaced with the more elegant:


use lib "/tmp";

Which is almost equivalent to our BEGIN block and is the recommended approach.

@alphabet_array = ('a' .. 'z');

-kalyan

Tuesday, August 09, 2005

/etc/shadow file structure

smithj:Ep6mckrOLChF.:10063:0:99999:7:::

As with the passwd file, each field in the shadow file is also separated with ":" colon characters, and are as follows:

  • Username, up to 8 characters. Case-sensitive, usually all lowercase. A direct match to the username in the /etc/passwd file.

  • Password, 13 character encrypted. A blank entry (eg. ::) indicates a password is not required to log in (usually a bad idea), and a ``*'' entry (eg. :*:) indicates the account has been disabled.

  • The number of days (since January 1, 1970) since the password was last changed.

  • The number of days before password may be changed (0 indicates it may be changed at any time)

  • The number of days after which password must be changed (99999 indicates user can keep his or her password unchanged for many, many years)

  • The number of days to warn user of an expiring password (7 for a full week)

  • The number of days after password expires that account is disabled

  • The number of days since January 1, 1970 that an account has been disabled

  • A reserved field for possible future use

/etc/passwd structure

@passwdArray=($name,$X,$uid,$gid,$gcos,$home,$shell);

-Kalyan

Monday, August 08, 2005

SQL tutorial

For a quick SQL tutorial,
http://www.1keydata.com/sql/sqlhaving.html

-Kalyan