Posts

Showing posts from March, 2019

Roots of a Polynomial Equation

The  solvers  module in SymPy implements methods for solving equations. Let's take an example of solving the equation of order 2. Equation : (x - 0.4)*(x + 0.65) - 1, Now we try to find positive roots of equation from sympy.solvers import solve from sympy import Symbol beta = Symbol('x',positive=True) #https://docs.sympy.org/latest/modules/solvers/solvers.html f =1 gammavalues = [0.4, 0.35, 0.3] for i in range(1,-1,-1): f = f*(beta-gammavalues[i]) f= f+1 f = f-2 print(f) beta = solve(f, beta) print(beta) output: (x - 0.4)*(x + 0.65) - 1 [1.00443569980765] just go through this link where you can find other important things like solving an algebraic equation, ODEs, PDEs https://docs.sympy.org/latest/modules/solvers/solvers.html

UNIT TESTS

Image
There are two types of engineers in this world(software context): type-1 just writes code and walks away, they assume everything will work fine. type-2 does the unit test and brings the piece of mind to type-1. Now we go through the unit testing in python, This helps us to the verify how well our code works with the required inputs. If we ask an engineer to write the code for the area of the circle, he writes it with no effort. from math import pi def circle_area(r): return pi*(r**2) #Test function will not be return by type-1 Engineers #Testing function radii = [2, 0, -3, 2+3j,True ,"radius"] message = "Area of circle with r = {radius} is {area}" for r in radii: A = circle_area(r) print(message.format(radius=r, area=A)) Output: we have written the testing code just to show you how the code goes wrong with the inputs. engineers just write the function and get relaxed. From the above i

Embedding the GitHub Gists codes into blogs

Image
Create the gist of your codes: Then get the embedding link. Click the HTML link and place the embedded link at the desired position. Code your code snippet appears as magic with git link in the below. Above process works for dynamic themes like Contempo in bloggers, but it fails for other dynamic themes so go for step 5. https://stackoverflow.com/questions/18788724/issues-adding-github-gist-to-my-blogusing-google-blogger/21355714#21355714  is the link where you can find the information to display the codes of Github with Gists in dynamic blogs.

Splitting criteria

Image
This package helps to find splitting criteria in C4.5 Information Gain ID3 uses information gain as its attribute selection measure. This measure is based on pioneering work by Claude Shannon on information theory, which studied the value or “information content” of messages. Let node N represent or hold the tuples of partition D. The attribute with the highest information gain is chosen as the splitting attribute for node N. This attribute minimizes the information needed to classify the tuples in the resulting partitions and reflects the least randomness or “impurity” in these partitions. Such an approach minimizes the expected number of tests needed to classify a given tuple and guarantees that a simple (but not necessarily the simplest) tree is found. The expected information needed to classify a tuple in D is given by: where pi is the probability that an arbitrary tuple inDbelongs to classCi and is estimated by |Ci,D|/|D|. A log function to the base 2 is used becaus

QUOTATION SERVER AND CLIENT

Image
A simple program of server and client where the server sent a good quote to the connected client immediately after the connection(as welcoming). Multiple Clients are handled using java multithreading concept, Used UDP datagram sockets, and text where quotes are stored.  The output of the above program: Outputs after quotes are completed: