Sunday, June 19, 2022

String concat() vs concat operators

 MDN has the following to say about string.concat():

It is strongly recommended to use the string concatenation operators (+, +=) instead of this method for perfomance reasons


Also see the link by @Bergi.


references:

https://stackoverflow.com/questions/16124032/js-strings-vs-concat-method


Pod Install on Apple M1 Chip

# Uninstall the local cocoapods gem
sudo gem uninstall cocoapods

# Reinstall cocoapods via Homebrew
brew install cocoapods

 references:

https://stackoverflow.com/questions/64901180/how-to-run-cocoapods-on-apple-silicon-m1

Installing MongoDB on Apple Mac M1 Pro

 Article on how to install mongodb on apple m1 using homebrew

Install homebrew from https://brew.sh/

Install xcode command line using

xcode-select --install

Now to install mongodb use

brew tap mongodb/brew

brew install mongodb-community@5.0

To check if mongodb has been installed use

mongo --version

to start mongoDB as macOS service use

brew services start mongodb-community@5.0

and to stop mongoDB to run as a background service use

brew services stop mongodb-community@5.0

Or, if you don't want/need a background service you can just run:

mongod --config /opt/homebrew/etc/mongod.conf

To run mongodb commands, open a new table and run mongo

To check your databases run show dbs

Full documentation here: https://docs.mongodb.com/manual/tutorial/install-mongodb-on-os-x/

references:

https://docs.mongodb.com/manual/tutorial/install-mongodb-on-os-x/

https://stackoverflow.com/questions/65357744/how-to-install-mongodb-on-apple-m1-chip

Sunday, June 12, 2022

AI/ML: Types of ensemble methods

BAGGing, or Bootstrap AGGregating. BAGGing gets its name because it combines Bootstrapping and Aggregation to form one ensemble model. Given a sample of data, multiple bootstrapped subsamples are pulled. A Decision Tree is formed on each of the bootstrapped subsamples. After each subsample Decision Tree has been formed, an algorithm is used to aggregate over the Decision Trees to form the most efficient predictor. The image below will help explain:


Random Forest Models. Random Forest Models can be thought of as BAGGing, with a slight tweak. When deciding where to split and how to make decisions, BAGGed Decision Trees have the full disposal of features to choose from. Therefore, although the bootstrapped samples may be slightly different, the data is largely going to break off at the same features throughout each model. In contrary, Random Forest models decide where to split based on a random selection of features. Rather than splitting at similar features at each node throughout, Random Forest models implement a level of differentiation because each tree will split based on different features. This level of differentiation provides a greater ensemble to aggregate over, ergo producing a more accurate predictor. Refer to the image for a better understanding.


Similar to BAGGing, bootstrapped subsamples are pulled from a larger dataset. A decision tree is formed on each subsample. HOWEVER, the decision tree is split on different features (in this diagram the features are represented by shapes).


References:

https://towardsdatascience.com/ensemble-methods-in-machine-learning-what-are-they-and-why-use-them-68ec3f9fef5f


AI/ML: Ensemble methods in machine learning

Ensemble methods is a machine learning technique that combines several base models in order to produce one optimal predictive model

A Decision Tree determines the predictive value based on series of questions and conditions. For instance, this simple Decision Tree determining on whether an individual should play outside or not. The tree takes several weather factors into account, and given each factor either makes a decision or asks another question.

When making Decision Trees, there are several factors we must take into consideration: On what features do we make our decisions on? What is the threshold for classifying each question into a yes or no answer? In the first Decision Tree, what if we wanted to ask ourselves if we had friends to play with or not. If we have friends, we will play every time. If not, we might continue to ask ourselves questions about the weather. By adding an additional question, we hope to greater define the Yes and No classes.

This is where Ensemble Methods come in handy! Rather than just relying on one Decision Tree and hoping we made the right decision at each split, Ensemble Methods allow us to take a sample of Decision Trees into account, calculate which features to use or questions to ask at each split, and make a final predictor based on the aggregated results of the sampled Decision Trees.

References:

https://towardsdatascience.com/ensemble-methods-in-machine-learning-what-are-they-and-why-use-them-68ec3f9fef5f


AI/ML: What is Durbin Watson Static Definition

The Durbin Watson (DW) statistic is a test for autocorrelation in the residuals from a statistical model or regression analysis. 

The Durbin-Watson statistic will always have a value ranging between 0 and 4. A value of 2.0 indicates there is no autocorrelation detected in the sample. Values from 0 to less than 2 point to positive autocorrelation and values from 2 to 4 means negative autocorrelation.

Autocorrelation, also known as serial correlation, can be a significant problem in analyzing historical data if one does not know to look out for it. For instance, since stock prices tend not to change too radically from one day to another, the prices from one day to the next could potentially be highly correlated, even though there is little useful information in this observation. In order to avoid autocorrelation issues, the easiest solution in finance is to simply convert a series of historical prices into a series of percentage-price changes from day to day.

references:

https://www.investopedia.com/terms/d/durbin-watson-statistic.asp

Thursday, June 9, 2022

Angular making input variable Optional

function example(x: number?, y?: string) {

 // …

}

“?” Suffix

The first one indicates a nullable parameter that can also be a number, undefined or null. But, the second argument is an optional, it can be a string or undefined.

Undefined vs Null

Again here some may not be aware of the difference between “undefined” and “null”. Undefined represents something that may not exist. Null is used for things that are nullable. So both are entirely different.

@Optional? As the official document says, Optional is a constructor parameter decorator that marks a dependency as optional. This clearly states that @Optional is used in the context of DI (Dependency Injection). 

@Injectable()

class Car {

    constructor(@Optional() public engine: Engine) {}

}

When @Optional is used, no exceptions occur even when the injected dependency is undefined. It treats the dependency as optional. Same thing happens if we replace @Optional annotation with “?”. The injector search for the dependency and when it is undefined, it will throw the exception.

Eventhough sometimes replacing these doesn’t make any difference in the way your code executes, it is necessary to understand that always good to follow best practices and the recommended ways as a good developer.

references:

https://medium.com/@angela.amarapala/understanding-the-usage-of-optional-and-nullable-in-typescript-826c1754df3