Monday, April 19, 2021

Using Vectorisation Effectively in Python and R – a revision example

 


    ========================================================

     Using Vectorisation Effectively in Python and R – instance example

    ========================================================


·        While performing Matrix Operations, such as Vector Multiplication , its very hard to consider that the computer does all the forms of hard work .  What does one need to do while working on numbers in a Vectorised form?

 ·        So , while one is working upon numbers , one needs to put the numbers in the form of matrices , vectors and constants and then one can sum , subtract , divide and then multiply the numbers .

 ·        These operations can be performed upon any number which is in the form of Vectors .

 ·        So , when one deals with these vectorised form of numbers in Machine Learning , then one should also have a good ( good is a relative value that lies in between novice and expert ) understanding and know how on how to feed the vectorised data to the algorithm over which the encoded function is going to work upon , which would help the programmer to know and understand the results obtained after the processing of the data is done .

 ·        In order to obtain a correct result , one may need to feed the right data to the right algorihtm .

 ·        In Python, Numpy package offers all the functionality needed to create and manipulate the matrices . The "ndarray" objects allow fast creation of an array , such as a multidimensional matrix by starting with data which are queued into the lists

 ·        The term "ndarray" means "n-dimensional array" which implies that one can create arrays of multiple dimensions like one-dimensional array , 2 dimensional array , 3 dimensional array and so on .

 

 

=========================================

Using a simple Vector for creation of a Numpy List

=========================================

 

import numpy as np

y = np.array([43, 45,47,49,51])

print(y)

print(y.shape)

 

Output

[43,45,47,49,51]

(5,)

 

==================================

==================================

 

* The method "shape" can promptly inform someone about the shape of a matrix . In the above given example , one can see that the shape of the matrix is just a one-dimensional entity which reports only three rows and no columns which means that the object is a vector

 * In order to create matrices made of rows and columns , one can make use of lists of list items .

 * The contents of the list inside the main list are the rows of one's matrix

 

==================================

==================================

import numpy as np

X = np.array([1.1,1,545,1],[4.6,0,345,2],[7.2,1,754,3])

print(X)

 

==================================

==================================

 * The output of the following operation would yield a vector which one can reshape into any desired form of rows and columns .

 * Here , the numbers are filled into the new matrix stacked into it in the form of row data which is occupied from the top most to the lowermost elements of the array which are stored in the output object "X" which would store in it all the elements in an iterative manner containing all the elements in i,j manner . Elements in an iterative manner containing all the elements in i,j manner .

 * Operations with addition and subtractions with scalars using the numpy "ndarray" is the best method of performing any operation .

 

* One can do the following operation - sum , subtract , multiply or divide using the severall standard operators applicable over Python language in the given manner . Lets take two data-array objects .. a and b

 ==================================

a = np.array([[1,1],[1,0]])

b = np.array([[1,0],[0,1]])

print(a - b)

[[ 0 1] [1 -1]]

==================================

a = np.array([[0,1],[1,-1]])

print(a * -2)

[[ 0 -2 ]

[ 2 -2 ]]

==================================

 * In order to perform multiplication on vectors and matrices , one needs to use the "np.dot" function . The input for this function is two arrays which are of compatible sizes to multiply according to the given order

 ==================================

X = np.array([[4,5],[2,4],[3,3]])

b = np.array([3,-2])

print(np.dot(X,b))

[ 2 -2  3 ]

B = np.array([3,-2],[-2,5])

print(np.dot(X,B))

 ==================================


 * The same form of multi-dimensional array output can be also produced by an array which one can find in the below set of code . One does not need any additional set of libraries while using R , R performs the tasks using standard functions as given in the below set of code .

 

* One can define the dimensions of one's vector using the "length()" function . But one can use the dis() function instead for the matrices , because applying the length() function to a matrix shows the output to carry only some number of elements in it .

 


Ref : Machine Learning in R and Python - 

Friday, April 16, 2021

Python Program to create a Static Method - with sample code

 

Python Program to create a Static Method

 

# A Python Program can be used to create a static method which can be used to calculate the square root value of a given number

static method for finding square root value

 

import math

class Sample:

@staticmethod

def calculate(x):

result = math.sqrt(x)

return result

 

# accept a number from keyboard

num = float(input('Enter a number:'))

# call the static method and pass the number

res = Sample.calculate(num)

print(' The square root of {} is {:.2f}'.format(num,res))

 

Output

Enter a number : 49

The square root of 49 is 7

 

Static Methods in Python - Example of a Static Method in a Class in Python

 


    Static Methods in Python


* One can use Static Methods while the class level but one may not involve the class or the constituting instances .

 

* Static Methods are used when one wants to process an element in relation to a class but does not need the class or its instance to perform any work .

 

* Example :

writing the environmental variables that go inside creation of a class , counting the number of instances of the class or changing an attribute in another class are the tasks related to a class .. such tasks can be handled by Static Methods

 

* Static Methods can be used to accept some values , process the values and then return the result .

 

* Also one could use Static Methods to accept some values , process the values and then return the result

 

* In this case , the involvement of neither the class nor the objects is of paramount importance .

 

* Static methods are written with a decorator @staticmethod above the methods

 

* Static Methods are called in the form of classname,method()

 

* In the following method , one is creating a static method "noObjects()" that counts the number of objects or instances created in MyClass . In MyClass , one can write a constructor that increments the class variable 'n' everytime an instance of the class is created . This incremented value of 'n' gets displayed by the "noObject()" method

  


 

Class Methods in Python - An example of creation of a Class Method in Python along with sample code

 


    Class Methods in Python


* These are the set of Methods are act on class level . Class Methods are the methods which act on the class variables or static variables .

 

* The Class Methods can be written using @classmethod decorator above them .

 

* For example , 'cls.var' is the format to refer to the class variable which includes methods which can be generally called using the classname.method()

 

* The process which is commonly needed by all the instances of the class is handled by the class methods

 

* In the given example below, one can see the instance of the class which is handled by the class methods . The same program can be developed using an example class which can be used in the following manner .

 

* In the example , one can refer to a sample Bird Class for more insight into the description and elaboration of a Method Class . All the birds in nature have only 2 wings (as we mostly see , but there are abberations ofcourse ). Here , one can take an instance of a Bird Class . All the Birds in Nature have 2 wings , therefore one can take 'wings' as a class variable and a copy of this class variable is

available to all the instances of the Bird Class . In this Bird class , we will create a hypothetical method which applies to the functions that a Bird can operate upon and thus will make use of this method that is "fly" method (... to fly above the sky ... fly rhymes good with sky .. please accept from me a satirical High of Hi ... I am poetic too you know :P)

 

* So where was I .. ya I was at the forefront of creation of a class which would take into its ambit a Bird which would have some generic applicable class variables all applicable to the organism class of Birds like all Birds have a pair of wings .. that makes the count to 2 . And birds fly .. which is a method attributed to birds . These two class variables and class methods would be made use of to instantiate a generic sample class of a Bird

 

* So lets create a Bird with two wings and this flies too (I am sorry to know that when God created a Bird like Penguin , God forgot to add the the instance function "fly" to its class genus ... therefore I shall also keep this off the charts for penguins,kiwis and take only those birds which can fly ... up above the sky )

 

* Without further ado .. lets get to this class creation which would take into effect all the common features of all the instances of a Bird Class

  

==================================

==================================

# understanding class methods

class Bird:

     # calling a class variable

     wings = 2

     # creating a class method @classmethod

     def fly(cls,name):

     print('{} flies with {} wings'.format(name,cls.wings))

 

#display information of 2 birds

Bird.fly('Garuda')

Bird.fly('Pigeon')

Bird.fly('Crow')

Bird.fly('HummingBird')

Bird.fly('Eagle')

 

==================================

==================================

Output

Garuda flies with 2 wings

Pigeon flies with 2 wings

Crow flies with 2 wings

HummingBird flies with 2 wings

Eagle flies with 2 wings

==================================

==================================

 

Thursday, April 15, 2021

Tech Commandments for a safer digital life - 5 principles to adhere to when using Internet

 

Tech Commandments for a safer digital life

 

* Technology has become a mammoth sized factor in our daily lives and to top it all , Technology is always on the change which means that one should always stay vigil of the changes happening around us as many perpetrators and miscreants are on the lookout for finding new ways to infiltrate into the loopholes that we set knowingly or unknowingly which leads them directly in hold of sensitive information which can lead to a big devastation if left unguarded and unprotected

 

* Some experts from leading security firms assert that one should always remember that any piece of our identity that we post online could eventually be used by fraudsters and hijackers / hackers to pervade into our online accounts for which one needs to keep oneself and connected members safe when online . These days bots ( trackers) can track any account and collect account information at any point of time

 

* Therefore in order to keep oneself on the guard and stay safe , some of the commandments that one needs to adhere to all the time are the following :

 

1) One should not overshare personal info

As many of us use high ended camera phones with very high or unlimited storage capacity , one gets into a clicking mode and becomes a self-proclaimed cameraman / photographer . But these days thanks to highly developed AI programs which can take even pictures as input parameters and retrieve all relevant information from the photo , one should stay vigil about the photos that one clicks , location , people in that photo , context and backdrop for that photo and several other factors before one gets into clicking mode to showcase one's photography skills

 

2) One should not use Weak and Easy to crack passwords

We all have a tendency to associate easy passwords which are small and easy to remember for all of our accounts as we normally want to skip ahead of all the mental work of recalling big and complex things whenever we want to get into our accounts .. be it social media accounts , bank accounts , insurance accounts

(and Swiss Bank Deposit accounts too .. ) . As mentioned , these days tracker bots can track all the gateways of access that an individual leaves upon their online pathways , so unrecognised and unregulated access into our trails can beonline pathways , so unrecognised and unregulated access into our trails can be

discovered by bots and provide the information to the collecting agency which is on the lookout of such paths which could be exploited . Many such agencies pass on these trail paths to hackers to peek into and steal out money / documents .. anything precious to them (remember .. "precious" of LOTR , one can turn into

Gollum for such "precious" things ) . Therefore , always make use of stronger and lengthier passwords which is one's somewhat safety check for stopping unwanted and malicious intrusion . Many people make use of password managers who make use of multiple accounts , but this is also vulnerable as these are stored in the form of either xml , json objects in the form of cookies which could be again collected from the browser plugins that one uses on a regular basis . Thats why , one should also try disconnecting from cookie storage from browser when one closes the session . And thus , the best thing to do is to note down all the important passwords over a piece of paper and keep them at a safe storage space .

 

 

3) One should use Multi-factor authentication or two-step verification

 

 

These days password comprehension can be done is so different forms by hackers that , if someone wants to any way hack into some account , then they will eventually get into the account and that too using several tools . Thats why most of the security experts recommend that one should make use of multifactor authentication (two-factor , three-factor etc) in order to access a given account which involves a user's verification before logging into account using a system of OTP over phone and authenticator apps that send temporary always changing codes that ensure that the user who is using the account is the real one and not a dummy or someone else

 

 

4) One should not share data about friends and Contacts

 

This comes as a completely new method of data siphoning which occurs when someone accepts any permissions to any app or software over the phone . This makes the app-owner a party to the shared information as requested by the app within the permission page of the application . Therefore, one thing that one needs to keep in mind is to keep a check over the permission page of the

applications that one installs .Best is .. one should try to limitise one's wants , keep few applications and software over one's phone and do not install those software that require a lot of permissions to be accepted before making use of the software .

 

5) One should always stay vigilant and skeptical

These days all the security experts accept the one rule of thumb for all security practices -- " Trust No One in this Greed Infested World" . Whenever you recieve any call ,message , email soliciting any personal information .. then do not trust any of message , email soliciting any personal information .. then do not trust any of the mails . This could be a phishing attack from someone who wants to profit out of undoubting people who out of trust and foolishness get entrapped in their untrustworthy traps , thereby losing security over their devices and mediums .Fraudsters nowadays can embed malware over legitimate looking emails within hyperlinks which once clicked could install unsuspecting software over your system all without anyone's coming to know of such a background activity running on your system . Therefore, whenever any suspicion occurs , always opt out of such apps , softwares , emails , anything (sigh ... wish I had known these earlier )

 

 

These days I personally feel .. the days of Nokia 1100 and Nokia 1600 , movies without real-looking CGI , games like Tetris and Mario were the best .

 

Fast Spreading Digital Adaptation in Emerging Nations and the associated "Theory of Everything" in the trade and commerce world - An article by Vivek Dash

 

Fast Spreading Digital Adaptation in Emerging Nations and the theory of Everything 

 

* Emerging economies have been struggling with growth through the 2010's and still the feeling of pessimism clouds over the present decade whether the steadfast growth trend could be seen to be going strong or whether the trend would be gauged down as it is being seen that People have accrued high amounts of debt during the ongoing pandemic which has become a detrimental factor to growth in not only emerging countries but also countries which are developed like USA , Russia , China , Japan , Germany , France , UK , Finland as questions over Growth tapping and keeping the same pace steady even during a pandemic period is of paramount importance to all

 * The answer to all the woes shrouding the question of development even during such cloudier and gloomy economic conditions, looming large and widespread is the harnessing of the Digital Revolution and Digital Adaptation. As most of the emerging nations have started adopting cutting edge technology at a much lower and lower cost which has allowed the countries to fuel domestic demand and overcome traditional obstacles to growth .

 * According to Reports , the number of smartphone users across the globe has skyrocketed from 150 million to 4 billion worldwide which approximates the total number of such people with a Smartphone device as nearly equals to or over half of the entire world's population . This has enabled most of the residents of the emerging world to access vital consumer and professional services over a phone which is no less than a computer in its kind and is much advanced than the personal computers which were there just a decade back .

 * According to reports from BCG - Boston Consulting Group , since 2014 more than 10,000 tech firms have been launched in emerging markets with half of them outside China

 * As per current trends and reports , India is having almost equal number of technology players as France and Germany and the number of such companies are growing much faster year on year .

* As per some key metrices and data collected by popular editorials , the onslaught and adaptation of digital revolution is much more in emerging economies than that of developed nations and has been growing at a much higher rate year on year .

 * Another report collected from some major editorials state that among the top 30 nations by revenue from digital services as share of GDP more than top 30 nations by revenue from digital services as share of GDP , more than half of them are in the emerging world . In such a scenario, it has emerged that Indonesia is much more advanced that countries such as Sweden and Finland which are Europe's most tech savvy nations

 * India ranks 12th in terms of digital revenues as a share of the economy

 * Since 2017 , digital revenue has grown in emerging countries at an annual pace of 26% compared to 11% in the developed nations

 * Led by e-commerce, the pace of growth in India has been even faster with revenues growing nearly 33% on year over year

* The European Centre for Digital Competitiveness scores G20 nations by the pace of progress in the digital ecosystem and "mindset" and thus puts four emerging nations in the top 5 category - Saudi Arabia , Indonesia , China and Argentina

 * The pressing question that has emerged from all this competitive talk is how have the developing nations adopted to digital technologies faster than the developed nations ? The widely acknowledged answer to such a question has come in the form of a simple answer that is Habit and tenacity. When some are wearing off and losing out on sheen as a result of their comfort seeking, some others rise who have the tenacity to struggle and get more resources for themselves as prize and with analogy it can be only reduced a cyclic process of growth and decay , decay and growth which applies to everyone be it person , society , principles , economies and even countries and continents .. and as well as the planet too (too much philosophy in an nutshell .... )

* The digital divide and access to information and services is narrowing down which used to be the key parameters upon which the developed nations had been brought up and this is trickling down to developing and under-developed nations too .

 * In the last decade alone , the number of internet users have doubled in the G20 nations which is astounding as a decade back access to internet was a distant dream for so many . (I first lay my hands upon internet services in the year 2008 , and the first time I got to own a computer was in the aftermath of 2003 ) . From that to this has been years marked with a boom in technological development which has been significantly very high in the last two decades alone compared to what the last century or any of the centuries ever saw in the history of the world .

 * Robustness of the governments to improve productivity by moving more and more services over to online format in order to make them more transparent and less vulnerable to corruption , which is one of the biggest deterrents / obstacles / vulnerabilities to corruption , which is one of the biggest deterrents / obstacles of doing business in the emerging world , which thereby creates a greater sense of trust and cooperation which in turn facilitates higher economic growth .

 * According to reports , the signle most factor for such kind of marked development to occur , the cost of starting or opening up business is a major driving factor which deters entrepreneurs from taking their feet out to start a business , innovation or self-sustained effort ; but since the cost of such factors has been in the decline in emerging or developing countries coupled with their in government support, guidance, motivation and cooperation such prospective entrepreneurs get a guided push for starting up as they can start their businesses and tools on their own and affordably , which these days could be just monitored and controlled within the grasp of their palms over a smartphone with internet .

 

* But as economies start evolving and growing, chances may arise that the things which catapulted such growth coupled with the rise of globalisation and access to great quality products from around the globe through way-to-go retail apps would slowly and slowly come down again and perhaps this could be a smaller miniscule side-effect of indigenisation which is again a cyclic effect which takes into factor indigenisation and globalisation which would also go all the time (You see ... one has to always keep in mind the cyclic effect of all things to understand all concepts of science , arts , culture , trade , war and even peace ... which encompasses the all round "theory of everything" )

 

 

Wednesday, April 14, 2021

Noticeable debacles on the part of public and political parties at the outset of Phase-2 of Covid pandemic in India ( a collective analysis )

 

                     Covid Phase-2 noticeable debacles

 

* Central Govt's decision to clear approvals on fast track basis for vaccines used in other countries is a welcome gesture in recognition of the sheer magnitude of the surging magnitude of the second Covid wave .

 

* It is also a grave issue for the officials to adhere to strict appropriate norms which needs to be followed both on the part of the officials as well as the public to adhere to best possible appropriate norms along with spread of the dangerous infection across the country

 

* Along with the Kumbh Mela of some sort , the Covid Tika Divas ensues after a grand function in the form of the "Paschim Bengal" elections which is again a grand amalgamation of people and opinions contained within a densely packed state population which is widely known for its celebrations be it religious ,spiritual , political or opinion based , the state celebrates all the forms of functions on a wide scale with mass gatherings and rallies of swarming people .

 

* This should have atleast called for sensitizing the general populace to adhere to all the mandatory guidelines , code of conduct for assemby and get togethers or rallies but it seems all these have again went for a toss as masses were noticed with no masks . Same situation is again on the notice in neighbouring Odisha where Panchayat Elections are to be held . Again precautions need to be set in place for people who attend any form of rallies or public gatherings as this is the utmost and basic need of the hour in order to curb the spread of the virus which travels in air and gets propagated from infected (be it mild/moderate/severe case) person to person

 

* I am no authority or person in charge to look upon the persisting conditions and what should someone be mindful about when people are in public during these pandemic periods of disease transmission but still then I think some there should be enforcement of law and order by people in charge of high offices within the confines of govenmental powers and positions to keep inculcating civic sense through all possible mediums of communication be in print or through telecom to convey the guidelines at all possible times as I and probably most of the people less or more similar to me have shorter memory spans and attention deficit disorder because of which getting misdirected is not so uncommon , but as because times are critical and the forecast for the second phase of pandemic

is an onset of a ghastlier trail of infections and deaths , a diligent adherence of strictness in the coming months is of paramount importance

 

* The current visuals from Gujarat , MP and Chattisgarh is not much encouraging and looks like the second wave has hit hard which is a grave warning to rest of the people in other states to adhere to proper Covid behaviour , mask up rather double mask up and to get vaccinated ... ( though I am yet to get vaccinated or receive vaccine, as I am not yet sure which vaccine should one take ... out of all the existing known options .. lol )

 

* Another funny thing I came across in one article is how some big politicians and Netas have started demanding VIP treatment from medicals and hospitals in the wake of this crisis which has infuriated some of the doctors and doctors associations.. Here the doctors forget to just chillax as we have been taught to idolise our great politicians , cricketers and filmstars as nothing less than demigods , and so getting a grand treatment from public including doctors , engineers is a sort of entitlement which nobody can negate .. so chillax .

 

* Another point that I would probably like to bring into picture is approval of foreign vaccines without passing through phase2 , phase-3 or whatsoever number of trials to be catered to India's population is a digrace from natural biological behaviour as what I presume is that the vaccines which have been procured from other countries may not be that much effective in our case as most of the people of India and south-east Asia have a different genetic makeup which is different from that of Americas , or that of Europe , Australia and hence administering the vaccine which has been created from samples belonging to other countries may not work out well ( Though I have to be optimistic about them as my domain and forte are different , hence I may not call myself an analyst in this field )

 

* I would acknowledge once again that some of the things that I have mentioned in this collected and referred article is an opinion of my own and may be seen as a case of counter opinion to popular opinion from a general public ( You can happily call me a dimwitand nota virtuoso if some of the points have not been put very appropriately as written by noted columnists and writers for lack of great jargons and plausible points or the lack of proper statistical figures ... its all upto the readers discretion )