Pages

Wednesday, April 22, 2020

Yantra Budhi -- Basic Introduction of Machine Learning



Machine Learning basically has two definitions. They are:

  1. Arthur Samuel -: "The field of study that gives computers the ability to learn without being explicitly programmed." This can be considered as an older, informal definition.
  2. Tom Mitchell explains how the computer program became a Machine learning one here -: "A computer program is said to learn from experience E with respect to some class of tasks T and performance measure P, if its performance at tasks in T, as measured by P, improves with experience E."
The second definition is considered in the modern world as it is having more clarity with the parameters which is more quantitative.


Now basically the question falls that how the machine is learning the things!


In an overview, it is being again subdivided as

  1. Supervised Learning
  2. Unsupervised Learning
From the name itself, some things are clear that one is by someone supervising the phenomenon of learning and the other there is no one to supervise the learning.

  1. Supervised Learning:
Now, normally one will think who is supervising. The machine itself is supervising but the data supervises machine to calculate and find the result. We have concrete data which by some equations or classification parameters we can reach to the result.

Again this is being subdivided as:
  • Regression :
    • Predicts a continuous-valued output. Many parameters will be there to find out a result.
    • Eg:- Given a picture find age.
  • Classification :
    • Separate the given data to discrete value of output.
    • Eg:- Given many pictures classify them to different age categories. 

2. Unsupervised Learning:

Now, what is unsupervised. Complete mystery of finding the result. Yes, it is not having any feedback to correct means no input data early available to supervise. The data which are available to work on as well as the scenario to separate and find a result from the data is new in this case. We can conclude Unsupervised Learning as if we have some data and we can separate it into meaningful information without any external input.

  • Clustering:
    • Given data and separate finding factors into clusters.
    • Eg:-Astronomical data to find similarities and cluster it.
  • Non-Clustering:
    • Given data instant of seperate time period or dimension and classify within from the data to find the difference.
    • Eg:- from two videos of same two person in an area at different angle directed with seperate camera and from this data distinguish the person and label in the video without any previous learning data.

Wednesday, February 18, 2015

Why header file?

Header file in a program will comprise of the files, function definitions and macros. Basically we will give same name for the c (or cpp file) and its corresponding header file. Like "ExInit.c" and "ExInit.h" file. So in this example, the preprocessor macros and functions that are used in the "ExInit.c" will be included in the "ExInit.h" .

Why we are using header file is a question since we can declare it in the c file itself. So what I found out from my experience is follows:

  1. Easy review since it is a structured one.
  2. To include in multiple file same group of files,functions or macros.
  3. To include inbuilt library of the c compiler.
  4. To reduce the code size by making proper conditional preprocessor statements.
  5. To improve compilation time.

Wednesday, February 11, 2015

Why AUTOSAR?

AUTOSAR( Automotive Open System Architecture) is basically to standardize cross ECU communication from different OEM manufacturers. The other main intention is to reduce the future development as all the different layers of the AUTOSAR will become compatible each other. Here the main idea is that most of the modules in controller are having basic functions as same. So even the function name and register mapped names in the lower layers are made same which makes the upper layers to work independently even changing the entire controller of the ECU.

Mainly the AUTOSAR layers are divided in top to bottom layer as :

  1. APP
  2. Run Time Environment (RTE)
  3. Service Layer
  4. ECU Abstraction Layer(ECAL)
  5. Microcontroller Abstraction Layer(MCAL)


The idea is so fine that in future it will be even good in implementing robotics, where the robot can change its parts which have same lower layer calls and every other components will remain the same as in the science fiction movies.

Sunday, December 28, 2014

Shift in Bluetooth

Normally when a communication technology is evolving it will try to increase its transmission rate. So the Bluetooth technology was also evolving similarly and the main evolutions are:

  1. First one was Basic Rate (BR) (the name came after the evolution into second one). It was having a physical layer with 1 Mbps.
  2. Secondly the Enhanced Data Rate(EDR) i.e. V.2.0 which increased the data rate upto 3Mbps.
  3. Then introduced an Alternative MAC PHY layer (AMP) on V.3.0 which eventually given a speed of about 54Mbps.
There needed a technology which uses much lesser power for prolonged use. Even though other low power RF wireless technologies were there, they were not having a unique encrypted protocol for communication. These made the researchers to think of making the Bluetooth Low Energy V4.0(BLE) protocol which is a cheaper low power protocol compared to older Bluetooth technology. For that they sacrificed the transmission rate but maintaining or improving other parameters. They reduced the transmission data rate to about 0.3Mbps which works under extreme low power. Today more BLE products are coming to market as Bluetooth Smart devices which needed lesser energy!

Tuesday, December 9, 2014

PIC16F877A I2C code Interfacing Library

Summary Of PIC16F877A:
======================
PIC16F877A is an 8 bit RISC microcontroller developed by Microchip. Only 35 assembly instructions are there for the microcontroller which makes it a better RISC controller with full functionalities.
The specifications are:
  • 20MHz maximum frequency.
  • 14.3KB of program memory.(can hold upto 8192 single word instructions)
  • 368 Bytes SRAM.
  • 256 EEPROM
  • 33 multiplexed I/O pins.
  • Eight 10 bit ADC channels.
  • 2 PWM.
  • 1 SPI & 1 I2C (MSSP works as either one at a time)
  • 1 USART
  • Two 8-bit timers & one 16-bit timer.
  • 2 Comparators 
What to Know before programming :
  • Uses MSSP(Master synchronous serial port) module.
  • Mode Supported
    • Master Mode
    • Multimaster mode
    • Slave mode
  • Addressing Supported
    • 7 - bit
    • 10 - bit
  • Registers used:
    • MSSP Control Register (SSPCON)
    • MSSP Control Register 2 (SSPCON2)
    • MSSP Status Register (SSPSTAT)
    • Serial Receive/Transmit Buffer Register(SSPBUF)
    • MSSP Shift Register (SSPSR) – Not directly accessible
    • MSSP Address Register (SSPADD)
      • slave mode - slave address
      • master mode - lower 7 bits acts as baud rate generator reload value.


Summary to develop code:
======================
You can use MPLAB IDE for the development. Assembly programming can be done using the IDE, but c coding requires additional compilers like MPLAB C and HI-TECH compilers. Now Microchip integrated the above two and made a new compiler named as MPLAB XC Compiler. There the free compiler is having lesser optimization (Only 25% compared to the PRO paid version). Means the level of code compression(which requires lesser ROM space) and accurate delay may have the difference. 


Master mode coding:
===========================
Please add i2c.c file in your c file containing the main function and use the code.

i2c.h
=======


void i2c_init();
void i2c_waitForIdle();
void i2c_start();
void i2c_repStart();
void i2c_stop();
unsigned char i2c_read( unsigned char ack);
unsigned char i2c_write( unsigned char i2cWriteData);

i2c.c
=====
/*
PIC16F877A Code for i2c in master mode.
Developed By Arun Chettoor
Can be used freely in any project under GPL license.
E-mail : arunkrishnanc@gmail.com
*/


#include"i2c.h"

#define clockFreq 10 //in MHz
#define i2cClock 0 // 0 for 100KHz and 1 for 400KHz

void i2c_init(){
char i2cFreq;
TRISC3=1;           // set SCL and SDA pins as inputs
  TRISC4=1;

  SSPCON = 0x38;      // set I2C master mode
  SSPCON2 = 0x00;

  #if i2cClock==0
  i2cFreq=100;
  #else
  i2cFreq=400;
  #endif

  SSPADD = (char)(((clockFreq*1000)/i2cFreq)-1);

  PSPIF=0;      // clear SSPIF interrupt flag
  BCLIF=0;      // clear bus collision flag
}

/*********************************************
To wait until i2c is idle.
*********************************************/

void i2c_waitForIdle()
{
 while (( SSPCON2 & 0x1F ) | STAT_RW ) {}; // wait for idle and not writing
}

/********************************************
To sent the start sequence
**********************************************/

void i2c_start()
{
 i2c_waitForIdle();
 SEN=1;
}

/*********************************************
To sent a repeated start sequence
*********************************************/

void i2c_repStart()
{
 i2c_waitForIdle();
 RSEN=1;
}

/*********************************************
To sent a stop sequence
**********************************************/

void i2c_stop()
{
 i2c_waitForIdle();
 PEN=1;
}

/*********************************************
Read char from i2c buffer register and return the value
*********************************************/

unsigned char i2c_read( unsigned char ack )
{
 unsigned char i2cReadData;

 i2c_waitForIdle();

 RCEN=1;

 i2c_waitForIdle();

 i2cReadData = SSPBUF;

 i2c_waitForIdle();

 if ( ack )
  {
  ACKDT=0;
  }
 else
  {
  ACKDT=1;
  }
  ACKEN=1;               // send acknowledge sequence

 return( i2cReadData );
}

/*********************************************
Write char data to i2c buffer

*********************************************/

unsigned char i2c_write( unsigned char i2cWriteData )
{
 i2c_waitForIdle();
 SSPBUF = i2cWriteData;
 i2c_waitForIdle();
 return ( ! ACKSTAT  ); // function returns '1' if transmission is acknowledged
}

Wednesday, November 26, 2014

Bash multiple cd using alias

We need to use cd .. to come back one directory or have to use cd ../../ to get back twice. So this can be resolved by a new command using the alias.
Create a new shell file and copy the following.

b.sh
=======
#!/bin/sh
_backfunc(){
if [ "$1" -eq 1 ]; then
cd ..
elif [ "$1" -eq 2 ]; then
cd ../..
elif [ "$1" -eq 3 ]; then
cd ../../..
elif [ "$1" -eq 4 ]; then
cd ../../../..
fi
}
alias back='_backfunc'

Now run this script in the current terminal as source b.sh
From now on you can go back upto 4 directory by using following statements:

back 1 # to go back 1 directory
back 2 # to go back 2 directory
back 3 # to go back 3 directory
back 4 # to go back 4 directory

You can add more statements like to go for a particular directory with a number or string by adding more elif statements on the above code. You can also change the "back" to whatever command you want by changing the "back"  in the code.

We can also implement multiple back from current directory by using while loop like shown below :
bloop.sh
==============
#!/bin/sh
_backfunc(){
count=$1
while [ "$count" -ne 0 ]
do
cd ..
count=$(( count - 1 ))
done
}

alias back='_backfunc'

To permanently make this alias you can add "source /home/USER/dir/bloop.sh" in the ~/.bashrc and from then on every new terminal will automatically detect the back statement. You can run the following script to add the file to the ~/.bashrc.

installbloop.sh
===============
 #!/bin/sh
#Put the bloop.sh and this file in the same directory to install at start up.
pw=$(pwd)
pw="source $pw/bloop.sh"
b="$HOME/.bashrc"
echo "$pw">>$b
echo "Added $pw to $b file\n"

This little bloop code can save your time a lot as it is for me!

Monday, November 24, 2014

source command in UNIX

Source command can be used to run the shell code in the current terminal. If we are running a bash script otherwise it will be running in a separate new terminal and after the end of the shell script it will come back to the current shell. So if we are writing the alias and all in the script it will not work on the current shell after the execution of the script since it is in separate context.

Syntax:
=======
source current.sh

current.sh - use back to go back once from the current directory
=========
#!/bin/sh
alias back="cd .."

# you can add the required shorts over this file and run by using the source to make it applicable to the current shell.

The other use of the source is to add separate bash script file which have some functions, alias or some other initialization and we need to use these in a new script. Here just we can use source command. For example :

new.sh - to go back twice from the current directory
=======
#!/bin/sh
source current.sh
back
back

Now call source new.sh to go back twice from the current directory..