Mutation

Write a program in Lisp to demonstrate the genetic operator mutation.

(Enter a population of binary strings. Perform mutation based on a random mutation point. Consider fitness value as the number of repetitions of a specified bit (say 1) in the string. Perform the evolution for a specified number generation.)


CODE:

(defun Muta(List)
(setq Cnt 0)
(setq newList '())
(setq mp (random (length List)))

(print "Mutation Point")
(prin1 mp)

                (loop
                                (when (equal (first List) nil) (return))
                                (if (equal mp Cnt)
                                                (if(equal (first List) 0)
                                                                (setq newList (cons '1 newList))
                                                                (setq newList (cons '0 newList))
                                                )
                               
                                                (setq newList (cons (first List) newList))
                                )
                               
                                (incf Cnt)
                                (setq List (rest List))
                )
               
                (setq List (reverse newList))
        (setq newList '())
                (print List)
)

(defun mainMuta (List1 List2 Gen)
(setq FVList1 0)
(setq FVList2 0)
(setq GenCntList1 0)
(setq GenCntList2 0)
(setq dplList '())

                (loop
                                (when (equal GenCntList1 Gen) (return))
                                (when (equal GenCntList2 Gen) (return))
                               
                                (setq FVList1 0)
                                (setq dplList List1)
                                (loop
                                                (when (equal (first List1) nil) (return))
                                                (if(equal (first List1) 1)(incf FVList1))
                                                (setq List1 (rest List1))
                                )
                                (setq List1 dplList)
                               
                                (setq FVList2 0)
                                (setq dplList List2)
                                (loop
                                                (when (equal (first List2) nil) (return))
                                                (if(equal (first List2) 1) (incf FVList2))
                                                (setq List2 (rest List2))
                                )
                                (setq List2 dplList)

                                (if (> FVList1 FVList2)
                                                (block blkOne
                                                                (incf GenCntList1)
                                                                (setq dplList List1)
                                                                (setq List1 (Muta List1))
                                                                (print "List1:-")
                                                                (prin1 List1)
                                                                (prin1 "List1 Generation Count:-")
                                                                (prin1 GenCntList1)
                                                )
                                                (block blkTwo
                                                                (incf GenCntList2)
                                                                (setq dplList List2)
                                                                (setq List2 (muta List2))
                                                                (print "List2:-")
                                                                (prin1 List2)
                                                                (prin1 "List2 Generation Count:-")
                                                                (prin1 GenCntList2)
                                                )
                                )
                )
)


(mainMuta '(1 2 3 4) '(5 6 7 8) 3)

OUTPUT:

"Mutation Point" 0
(0 2 3 4)
"List1:-" (0 2 3 4)"List1 Generation Count:-"1
"Mutation Point" 3
(5 6 7 0)
"List2:-" (5 6 7 0)"List2 Generation Count:-"1
"Mutation Point" 1
(5 0 7 0)
"List2:-" (5 0 7 0)"List2 Generation Count:-"2
"Mutation Point" 1
(5 1 7 0)
"List2:-" (5 1 7 0)"List2 Generation Count:-"3
NIL

Roulette Wheel

Write a program in Lisp to perform roulette wheel selection. (Enter a population of binary strings. Consider fitness value as the number of repetitions of a specified bit (say 1) in the string.)


CODE:

(defun strStg (strWord)
(setq stgCnt 0)
(setq lenCnt 0)
                (loop
                                (when (equal lenCnt (length strWord)) (return stgCnt))
                                (if (equal (char "1" 0) (char strWord lenCnt)) (incf stgCnt))
                                (incf lenCnt)
                )
)

(strStg "10001")

(defun RW (strOne strTwo strThree strFour strFive)
(setq Cnt 0)
(setq stgList '())

                (setq strOneStg (strStg strOne))
                (setq strTwoStg (strStg strTwo))
                (setq strThreeStg (strStg strThree))
                (setq strFourStg (strStg strFour))
                (setq strFiveStg (strStg strFive))

                (setq stgList (push strOneStg stgList))
                (setq stgList (push (+ strOneStg strTwoStg) stgList))       
                (setq stgList (push (+ strOneStg strTwoStg strThreeStg) stgList))
                (setq stgList (push (+ strOneStg strTwoStg strThreeStg strFourStg) stgList))
                (setq stgList (push (+ strOneStg strTwoStg strThreeStg strFourStg strFiveStg) stgList))

                (setq strSel (Mod (random 1000) (first stgList)))
                (print strSel)

                (loop
                                (when (equal (first stgList) nil) (return))
                                (if (>= strSel (first stgList))
                                                (block blkIf
                                                                (if(equal Cnt 0)(return strOne))
                                                                (if(equal Cnt 1)(return strTwo))
                                                                (if(equal Cnt 2)(return strThree))
                                                                (if(equal Cnt 3)(return strFour))
                                                                (if(equal Cnt 4)(return strFive))
                                                )
                                )
                                (setq stgList (rest stgList))
                                (incf Cnt)
                )
)

(RW "100110" "100101" "001010" "010101" "100001")

OUTPUT:
---- Done ----

1

---- Done ----

7
"010101"

A fuzzy system is a structured Numerical estimator in LISP example Inverted Pendulum

Write a program in Lisp to demonstrate that a fuzzy system is a structured
Numerical estimator-using example of controlling an inverted pendulum.
(Enter two strings for angle of pendulum θ and angular velocity Δθ.

Convert them into strings of fuzzy using five fuzzy set values NM(Negative medium), NS (Negative Small), ZE(Zero), PS (Positive Small) and PM ( Positive Medium). Apply FAM rules to find the output values v,the current to the motor control of the pendulum to each input set of (θ,Δθ). Create a string of fuzzy output values of the current.)

(defun FAM (angPen anguVel)
                (cond
                                ((equal angPen "NM")
                                                                (cond
                                                                                ((equal anguVel "NM") nil)
                                                                                ((equal anguVel "NS") nil)
                                                                                ((equal anguVel "ZE") (print "PM"))
                                                                                ((equal anguVel "PS") nil)
                                                                                ((equal anguVel "PM") nil)
                                                                )
                                )
                                ((equal angPen "NS")
                                                                (cond
                                                                                ((equal anguVel "NM") nil)
                                                                                ((equal anguVel "NS") nil)
                                                                                ((equal anguVel "ZE") (print "PS"))
                                                                                ((equal anguVel "PS") nil)
                                                                                ((equal anguVel "PM") nil)
                                                                )
                                )
                                ((equal angPen "ZE")
                                                                (cond
                                                                                ((equal anguVel "NM") (print "PM"))
                                                                                ((equal anguVel "NS") (print "PS"))
                                                                                ((equal anguVel "ZE") (print "ZE"))
                                                                                ((equal anguVel "PS") (print "NS"))
                                                                                ((equal anguVel "PM") (print "NM"))
                                                                )
                                )
                                ((equal angPen "PS")
                                                                (cond
                                                                                ((equal anguVel "NM") nil)
                                                                                ((equal anguVel "NS") nil)
                                                                                ((equal anguVel "ZE") (print "NS"))
                                                                                ((equal anguVel "PS") nil)
                                                                                ((equal anguVel "PM") nil)
                                                                )
                                )
                                ((equal angPen "PM")
                                                                (cond
                                                                                ((equal anguVel "NM") nil)
                                                                                ((equal anguVel "NS") nil)
                                                                                ((equal anguVel "ZE") (print "NM"))
                                                                                ((equal anguVel "PS") nil)
                                                                                ((equal anguVel "PM") nil)
                                                                )
                                )
                )
)

(FAM "NM" "ZE")

OUTPUT:
---- Done ----
FAM
---- Done ----
"PM"


logistic, threshold, hyperbolic-tangent, linear, exponential, sigmoid functions

Write a program in Lisp to demonstrate working of an artificial neuron.

(Enter an input vector X and weight vector W. Calculate weighted sum  XW. Transform this using signal or activation functions like logistic,threshold, hyperbolic-tangent, linear, exponential, sigmoid etc and display the output.)


(defun nnFunctions (actSignList wghtList c n)
(setq wghtSum 0)
(setq resFunc 0)
            (loop
                        (when (equal (first actSignList) nil) (return))
                        (setq wghtSum (+ wghtSum (* (first actSignList) (first wghtList))))
                        (print wghtSum )
                        (setq actSignList (rest actSignList))
                        (setq wghtList (rest  wghtList))
            )
            (print "Logistical Signal Function")
            (print (/ 1 (+ 1 (exp (- 0 (* c wghtSum))))))

            (print "Hyperbolic tangent Signal Function")
            (print (tan (* 10 wghtSum)))
           
            (print "Threshold Linear Signal Function")
                        (if (<= 1 (* c wghtSum)) (print 1) (print 0))
           
            (print "Linear Signal Function")
            (print (* c wghtSum))

            (print "Threshold Exponential Signal Function")
            (print (min 1 (exp (* c wghtSum))))

            (print "Threshold Distribution Signal Function")
            (print (max 0 (- 1 (exp (- 0 (* c wghtSum))))))

            (print "Ratio Polynomial Signal Function")
            (print (max 0 (/ (expt wghtSum n) (+ c (expt wghtSum n)))))
)

(nnFunctions '(1 2 3) '(2 3 4) 5 4 )

OUTPUT:
---- Done ----
0
---- Done ----
2
8
20
"Logistical Signal Function"
1.0
"Hyperbolic tangent Signal Function"
-1.7925274837903817
"Threshold Linear Signal Function"
1         
"Linear Signal Function"
100
"Threshold Exponential Signal Function"
1
"Threshold Distribution Signal Function"
1.0
"Ratio Polynomial Signal Function"
32000/32001
32000/32001

Count the number of repetitions of each element in the list in LISP

Write a program in Lisp to enter a number n and create a list of length n of repeated elements. Count the number of repetitions of each element in the list. Display the count value of each element in character.

( Eg (1 2 1 1 3) should give the output “element 1: three times”).


(defun Num()
(print "Enter a Number:")
(setq a(read))
(loop for i from 0 to a collect(random 3)
)
)
NUM

(defun occurence()
(setf b(Num))
(format t "Elements are : ~S ~%" b)
(setq m(count 0 b))
(format t "Element : ~R ~R times ~%" 0 m)
(setq c(count 1 b))
(format t "Element : ~R ~R times ~%" 1 c)
(setq d(count 2 b))
(format t "Element : ~R ~R times ~%" 2 d)
(setq e(count 3 b))
(format t "Element : ~R ~R times ~%" 3 d)
)
OCCURENCE



Average, Factorial and Fibonacci using LISP


Average

(defun average(n1 n2)
           (setq avg (/  (+ n1 n2) 2))
)

Factorial

(defun factorial(n)
          (if(= n 0 ) 1
                 (* n (factorial(- n 1)))
          )
)


Fibonacci

(defun fibonacci()
         (format t "Enter the limit : ")
         (setf n(read))
         (format t "Fibonacci series : ")
         (format t "0 1")
         (setf a 0)
         (setf b 1)
         (do ((i 3(+ i 1))) ((> i n))
                (setf c (+ a b))
                (format t " ~d" c)
                (setf a b)
                (setf b c)
         )
)

Addition, subtraction, multiplication & division of two numbers using LISP

Write and execute the statements for the following in LISP:

Addition,  subtraction, multiplication & division of two numbers.


(setq no1(read))
12
12

(setq no2(read))
30
30

(+ no1 no2)
42

(- no2 no1)
18

(* no1 no2)
360

(/ no2 no1)
5/2


3 ways to speed up your old smartphone

As smartphones age, they tend to slow down and lag too much while performing the simplest of tasks. But worry not, you can make your old gadget operate faster, just follow these three tips:

Updates
Firmware updates take care of lags, bugs, and other issues that you may not be aware of. Such issues crop up with reasonable frequency, so updating regularly will ensure the best performance for your phone.

Memory issues
Low internal memory might be the reason behind any severe lag that your phone is experiencing. Move your media (pictures, MP3 files, videos, and so forth) to the external memory, usually an SD card. Some low-end and mid-range smartphones might already have low internal memories, in which case, moving your files to the SD card won't help that much.

Apps
The application store of your phone, regardless of which OS it uses, will have plenty of apps that can help boost your phone's performance. Task managers help you monitor and close unnecessary processes. This frees up some RAM memory, and so, the phone will run faster. A good antivirus application will scan your phone for any possible viruses and malwares, which can also slow down your phone.

Convert Service pack 2 to service pack 3

~ go to start---->Run--> type the word Regedit



~ Your windows Registry Editor will open,



~ Go to HKEY_LOCAL_MACHINE\SYSTEM\ CurrentControlSet\ Control\ Windows



~ Than please modify “CSDVersion” from “0×00000200” (SP2) to the Windows XP SP3 value of “0×00000300” and than reboot your system.



Now your Window has been upgraded to SP3 and you will be able to installed various advance softwares.

Factorial Of A Number Recursion Function

Write a program to find factorial of the given number.
Recursion: A function is called'recursive 'if a statement within the body of a function calls the same function. It
is also called'circular definition '. Recursion is thus a process of defining something in terms of itself.
Program: To calculate the factorial value using recursion.
#include

int fact(int n);
int main()
{
int x, i;

printf("En ter a value for x: \n");
scanf("%d" ,&x);

i = fact(x);

printf("\n Factorial of %d is %d", x, i);
return 0;
}
int fact(int n)
{
/* n=0 indicates a terminatin g condition */
if (n
return (1);
}
else
{
/* function calling itself */
return (n * fact(n - 1));
/*n*fact(n -1) is a recursive expression */
}
}
Output:
Enter a value for x:
4
Factorial of 4 is 24
Explanatio n:
fact(n) = n * fact(n-1)
If n=4
fact(4) = 4 * fact(3) there is a call to fact(3)
fact(3) = 3 * fact(2)
fact(2) = 2 * fact(1)
fact(1) = 1 * fact(0)
fact(0) = 1
fact(1) = 1 * 1 = 1
fact(2) = 2 * 1 = 2
fact(3) = 3 * 2 = 6
Thus fact(4) = 4 * 6 = 24
Terminatin g condition( n
infinite loop.

Simple Slider using JQuery Animation

Step 1 : Create a html file and add the following script tag in head section
             <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" type="text/javascript">

Step 2 : add the following code to display the images
           
             <div id="wrapper">
<div id="slide">
<img src="7.JPG" width="200px" height="200px" />
<img src="8.JPG" width="200px" height="200px" />
<img src="9.JPG" width="200px" height="200px" />
<img src="11.JPG" width="200px" height="200px" />
<img src="12.JPG" width="200px" height="200px" />
</div>
   </div>

Step 3 : add the following code for next and previous button
            <div id="buttons">
<a href="javascript:void(0)" id="prev"><span style="text-decoration:none;"> < </span></a>
<a href="javascript:void(0)" id="next"><span style="text-decoration:none;"> > </span></a>
   </div>

Step 4: add the following css code
            *{
margin: 0 auto;
padding:0;
        }

#wrapper{
width:600px;
overflow:hidden;

}
#slide{
width:900px;
overflow:hidden;
height:210px;
position:relative;
}

#buttons{
position: relative;
width: 600px;
}


Step 5: add the following jquery to animate slide the images
            $(document).ready(function(){
               var timages = 5; <!-- timages = total number of images -->
var simages = 3; <1-- simages = number of images to show -->
var limages = timages-simages; <!-- limages = number of images remaining i.e. 5-3=2 -->
var cimages = 0; <!-- cimages = current images -->
$("#prev").click(function(){
cimages --;
if (cimages < 0)
{
cimages = 0
}
var posx = cimages* 200;
//showInputText();
$("#slide").animate({left:"-"+posx+"px"}, 500 )
});

$("#next").click(function(){
cimages ++;
if (cimages > limages)
{
cimages = limages
}
var posx = cimages* 200;
//showInputText();
$("#slide").animate({left:"-"+posx+"px"}, 500 )
})
 })



Your final code should look like this

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" type="text/javascript"></script>

<title>Untitled Document</title>
<style>
*{
margin: 0 auto;
padding:0;
}

#wrapper{
width:600px;
overflow:hidden;

}
#slide{
width:900px;
overflow:hidden;
height:210px;
position:relative;
}

#buttons{
position: relative;
width: 600px;
}
</style>
<script>
$(document).ready(function(){
var timages = 5;
var simages = 3;
var limages = timages-simages;
var cimages = 0;
$("#prev").click(function(){
cimages --;
if (cimages < 0)
{
cimages = 0
}
var posx = cimages* 200;
//showInputText();
$("#slide").animate({left:"-"+posx+"px"}, 500 )
});

$("#next").click(function(){
cimages ++;
if (cimages > limages)
{
cimages = limages
}
var posx = cimages* 200;
//showInputText();
$("#slide").animate({left:"-"+posx+"px"}, 500 )
})
})

</script>
</head>

<body>
<div id="wrapper">
<div id="slide">
<img src="7.JPG" width="200px" height="200px" />
<img src="8.JPG" width="200px" height="200px" />
<img src="9.JPG" width="200px" height="200px" />
<img src="11.JPG" width="200px" height="200px" />
<img src="12.JPG" width="200px" height="200px" />
</div>
</div>
<div id="buttons">
<a href="javascript:void(0)" id="prev"><span style="text-decoration:none;"> < </span></a>
<a href="javascript:void(0)" id="next"><span style="text-decoration:none;"> > </span></a>
</div>
</body>
</html>


Speech Recognition: javax.speech.recognition

Hello World!


The following example shows a simple application that uses speech recognition. For this application we need to define a grammar of everything the user can say, and we need to write the Java software that performs the recognition task.
A grammar is provided by an application to a speech recognizer to define the words that a user can say, and the patterns in which those words can be spoken. In this example, we define a grammar that allows a user to say "Hello World" or a variant. The grammar is defined using the Java Speech Grammar Format. This format is documented in the Java Speech Grammar Format Specification.


Place this grammar into a file.


grammar javax.speech.helloworld;

public <sentence> = hello world | good morning |
                                      hello mighty computer;
This trivial grammar has a single public rule called "sentence". A rule defines what may be spoken by a user. A public rule is one that may be activated for recognition.

The following code shows how to create a recognizer, load the grammar, and then wait for the user to say something that matches the grammar. When it gets a match, it deallocates the engine and exits.


import javax.speech.*;
import javax.speech.recognition.*;
import java.io.FileReader;
import java.util.Locale;

public class HelloWorld extends ResultAdapter {
 static Recognizer rec;

 // Receives RESULT_ACCEPTED event: print it, clean up, exit
 public void resultAccepted(ResultEvent e) {
  Result r = (Result)(e.getSource());
  ResultToken tokens[] = r.getBestTokens();

  for (int i = 0; i < tokens.length; i++)
   System.out.print(tokens[i].getSpokenText() + " ");
  System.out.println();

  // Deallocate the recognizer and exit
  rec.deallocate();
  System.exit(0);
 }

 public static void main(String args[]) {
  try {
   // Create a recognizer that supports English.
   rec = Central.createRecognizer(
       new EngineModeDesc(Locale.ENGLISH));
 
   // Start up the recognizer
   rec.allocate();
 
   // Load the grammar from a file, and enable it
   FileReader reader = new FileReader(args[0]);
   RuleGrammar gram = rec.loadJSGF(reader);
   gram.setEnabled(true);

   // Add the listener to get results
   rec.addResultListener(new HelloWorld());

   // Commit the grammar
   rec.commitChanges();

   // Request focus and start listening
   rec.requestFocus();
   rec.resume();
  } catch (Exception e) {
   e.printStackTrace();
  }
 }
}



This example illustrates the basic steps which all speech recognition applications must perform. Let's examine each step in detail.

Create: The Central class of javax.speech package is used to obtain a speech recognizer by calling the createRecognizer method. The EngineModeDesc argument provides the information needed to locate an appropriate recognizer. In this example we requested a recognizer that understands English (since the grammar is written for English).

Allocate: The allocate methods requests that the Recognizer allocate all necessary resources.

Load and enable grammars: The loadJSGF method reads in a JSGF document from a reader created for the file that contains the javax.speech.demo grammar. (Alternatively, the loadJSGF method can load a grammar from a URL.) Next, the grammar is enabled. Once the recognizer receives focus (see below), an enabled grammar is activated for recognition: that is, the recognizer compares incoming audio to the active grammars and listens for speech that matches those grammars.

Attach a ResultListener: The HelloWorld class extends the ResultAdapter class which is a trivial implementation of the ResultListener interface. An instance of the HelloWorld class is attached to the Recognizer to receive result events. These events indicate progress as the recognition of speech takes place. In this implementation, we process the RESULT_ACCEPTED event, which is provided when the recognizer completes recognition of input speech that matches an active grammar.

Commit changes: Any changes in grammars and the grammar enabled status needed to be committed to take effect (that includes creation of a new grammar).
Request focus and resume: For recognition of the grammar to occur, the recognizer must be in the RESUMED state and must have the speech focus. The requestFocus and resume methods achieve this.
Process result: Once the main method is completed, the application waits until the user speaks. When the user speaks something that matches the loaded grammar, the recognizer issues aRESULT_ACCEPTED event to the listener we attached to the recognizer. The source of this event is a Result object that contains information about what the recognizer heard. The getBestTokensmethod returns an array of ResultTokens, each of which represents a single spoken word. These words are printed.
Deallocate: Before exiting we call deallocate to free up the recognizer's resources.


Credits : www.ling.helsinki.fi