Tuesday, December 12, 2023

 

This is a continuation of previous articles on IaC shortcomings and resolutions. One of the favored patterns is the shared nothing pattern that provides complete isolation, protection from cross-contamination, and improved scalability and security. Case in point is the app services to app service plan mapping.

If there is a one-to-one relationship between app services and their plans, then each app service plan provides independent scalability for the app service. The use of a subnet with the app service plan allows customizations for just that app service including its inbound and outbound connections.

The other pattern is a shared pattern. For example, a gateway might have more than a dozen app services as its backend members and each member might be allowing public access. If the gateway must consolidate access to all the app services, then there are changes required on the gateway to route traffic to each app service as intended by the client and a restriction on the app services to allow only private access from the gateway.  

Between the application of these patterns, one of the factors determining the outcome is their purpose and utility. For example, a smaller subnet with only /28 suffix will have a smaller ip range and these can be issued as many as needed from the same virtual network. On the other hand, consolidation of app service plans across app services allows us to use just one subnet as outbound for traffic from all the app services because the VM is assigned only one NIC card This is favored when the set of app services belong to the same category and the traffic does not impact the performance of the app services.

An upgrade of all the subnets to the latest IaC definitions and the creation of new subnets to replace the non-functional subnets will be an ongoing maintenance. As the deployment grows with age, the versions of the toolset and definitions also change. New properties get added while the old ones get deprecated. Changing the definitions poses a risk across many resources and resource types that are hosted on the subnets, so they must be changed methodically.

The changes could be initiated progressively and in an incremental manner such that the round of tests is minimized and only applied to the changes made. The first step is to update the toolset before any changes are made. Then the existing definitions are assigned to a reference for their source before the new definition is used. If they did not have a reference, they would have pointed to the latest and updating the source to a new definition would affect more resources than intended. Next, the common definition for the subnet was updated, and a new tag was generated so that it could be referenced only from those callers that required the new definition. Once the reference is available, all the resources in the deployment that require the new definition are pointed to the new reference

Some app services might start out the same way but end up differently.  The initialization of resources as well as their potential growth are important factors for the choice of patterns.

In this way, the choice of patterns must be decided on a case-by-case basis.

 CodingExercise-12-12b-2023.docx

 

 

Monday, December 11, 2023

 

Who doesn’t like a four day week? But has it ever been analyzed as much as Joe Sanok does in his book titled “Thursday is the new Friday” and published by HarperCollins Leadership, 2021. He is a mental health professional and the host of the “Practice of the Practice” podcast. He argues that the five-day work week must undergo an overhaul not just because it is a remnant of a bygone era but also because it provides an opportunity to take control of one’s schedule and spend more time to better match how the brain works. This improves productivity and reduces stress leading to a healthier and happier life.

Covid-19 has recently demonstrated that working remotely is favored over 9-5 five-days-a-week. In many cases, this improves productivity and job satisfaction. The 9-5 five-day-workweek was popularized by Henry Ford in 1926 and has its roots as early as 1886 for safer worker conditions at Chicago’s Haymarket Square. But in the current times, the author recommends us to slow down, set boundaries and shrink the work week to spend more time with family, practice self-care and make a meaningful contribution to our world.

Before we jump into it, we should measure our individual success. There are three internal inclinations that are good predictors: “curiosity”, an “outsider approach”, and the ability to “move on it”. These inclinations come from DNA, upbringing, culture and experience. If the current inclinations are not serving us well, we must develop specific inclinations to do our best work.

The author contends that those who are curious and proceed despite the warnings are the ones that truly make an impact. Author Isaac Asimov once said that the most exciting phrase to hear in science, the one that heralds discoveries is not ‘Eureka’ but ‘That’s funny.’

An outsider approach starts to die when we think conforming is safer than being unique. Humans are social animals who gravitate towards group membership and try to avoid social rejection. Building once’s immunity to rejections helps us reduce feelings of vulnerability. Mindfulness practices such as meditation also reduce psychological vulnerability.

Moving on launching a product or service by striking a balance between speed and accuracy is recommended. A minimum viable product aka MVP leads to faster improvements over several iterations and avoids the paralysis for attaining perfection.  Joe says that the internal inclination of jumping before we are ready is about standing up against the predominant narrative that we ‘practice until perfect’. When we move on it before we are ready, it gives us a download of information that informs our path to action. The three questions to launch rule can help articulate this:

Describe the pain – what does it take in terms of effort to realize this product?

Describe the magical product – what product is the best solution to the problem?

Describe the pay - How much would you pay for what you just described?

Taking time to recharge, recover and gain creative insights also helps avoid burnout. We have become busy to the point where we cannot keep up and this makes feel bad. Instead, the three tenets of eliminating clutter, anticipating problems and casting away 24/7 profits outlook will help boost productivity.  We could keep personal key performance indicators aka KPIs such as a weekly yoga class, regular snowboarding morning, or a daily coffee with a friend with the side-benefit of a fresh outlook and perspective, can bring joy and freedom.

Once we start measuring how much of our time is eaten away by others, we will be best positioned to decide how we want to slow down. Slowing down optimizes the brain power just as the following steps in the FIRST model boost business growth.

Fruit: low hanging fruit – enhance the areas of business that are doing well.

Inflect: act as if  - manifest the goals by acting as someone who has already reached them would

Reinvest: make the business stronger – Peter Drucker, the management guru, suggested “Do what you do best and outsource the rest”

Specialize: stand out and microniching – select the activities and client that maximize joy and benefits

Time-limited: six- and twelve- month goals – prioritize shortterm goals to remain focused.

Cycles of sprint and rest can also be alternated.

Sunday, December 10, 2023

 

Crisis is a situation that requires a variety of decisions and responses. One cannot expect a level of predictability and order that organizational leaders are accustomed to during normal business operations. Take the case of January 1993 when a gunman killed seven people in a suburb of Chicago and how the administrative executive and spokesperson for the police, Deputy chief Walter Gasior, played many roles simultaneously. He had to deal with grieving families and a frightened community, help direct operations of the police department, and take questions from the media. In this example, Gasior was ultimately successful, but common leadership principles failed when they should have prevailed.

When the circumstances are fluid, the Cynefin framework (pronounced “ku-nev-in”) proposed by David Snowden and Mary Boone as early as 1999, provides a framework that allows executives to see things from new viewpoints, assimilate complex concepts and address real-world problems and opportunities. This enhances communications and helps build an understanding of the context in which the leaders operate.

Organization consultant Jos Postma elaborates on this framework by drawing experiences and knowledge from Lean, Agile, Scrum and other methodologies, in his recent book, titled “The Cynefin framework in 60 minutes” and published by BeWiseMedia in 2023. He calls it a “meta-framework” that facilitates decision-making within each strategy and improve outcomes. It can be used to assess a problem’s complexity and to improve responses. It determines the domain for a problem and offers practical insights for strategic planning, risk management, and decision making. It plays a role even in product development and guides crisis and change management. When making decisions or facilitating team discussions, it serves as a tool by itself and complements other frameworks. When the nature of the problems is understood, solutions fall in place.

This framework categorizes problems in five domains: 1. Clear/simple/obvious where the cause and effect are known, 2. Complicated where there are indirect or less obvious relationships that require a “Sense-Analyze-Respond” approach, 3. Complex situations where the cause-effect relationships are neither direct nor indirect and can only be revealed in hindsight but can be influenced by “Probe-Sense-Respond’ technique, 4. Chaotic – where the relationships will not become clear immediately or even later but can be remedied by “Act-Sense-Respond” approach, and finally, 5. Apex/Disorder situations where a situation does not fall into any of the earlier four and a leader must use creativity to categorize the domain.

Fundamental to this framework is a recognition that different situations require different approaches and the categories are not static but dynamic. Studying the problem helps determine its domain. For example, a sales decline might be due to familiar seasonal changes or new from disruptive competitors. The approach to a studied situation usually involves 1. Domain identification in Cynefin framework, 2. Selecting actions, and 3. Adaptation. In this way, it acknowledges and embraces complexity. It must be noted that this is a journey not a state.

In the context of product development, this framework complements existing methodologies by understanding the nature of the challenges and requirements. For example, Agile methodology aligns well with Cynefin in the Complex domain and like Lean, it delivers maximal value with minimal waste. The decisions are shaped from early stages of conception to managing risk during launch.

Crisis situations often begin in the Chaotic Domain but can be shifted into the Complex domain. Leaders are best served to take an approach of guided emergence, allowing new order to emerge from interactions within the system rather than imposing from above. The global response to COVID-19 pandemic provides a worthwhile example in this regard.

This classification system successfully applies to a large set of diverse problems and provides a technique to hone the right contextual approach. If the challenges grow volatile, uncertain, complex and ambiguous or VUCA for short, then this framework emphasizes exploration to discern emerging patterns. Perseverance, an open-mindset and practice will bring mastery of this valuable tool.

Leaders who recognize that the world is often irrational and unpredictable will find the Cynefin framework particularly useful.

Previous Book Summaries: BookSummary24.docx

Saturday, December 9, 2023

Number of Ways to Split Array

 


You are given a 0-indexed integer array nums of length n.

nums contains a valid split at index i if the following are true:

  • The sum of the first i + 1 elements is greater than or equal to the sum of the last n - i - 1 elements.
  • There is at least one element to the right of i. That is, 0 <= i < n - 1.

Return the number of valid splits in nums.

 

Example 1:

Input: nums = [10,4,-8,7]

Output: 2

Explanation:

There are three ways of splitting nums into two non-empty parts:

- Split nums at index 0. Then, the first part is [10], and its sum is 10. The second part is [4,-8,7], and its sum is 3. Since 10 >= 3, i = 0 is a valid split.

- Split nums at index 1. Then, the first part is [10,4], and its sum is 14. The second part is [-8,7], and its sum is -1. Since 14 >= -1, i = 1 is a valid split.

- Split nums at index 2. Then, the first part is [10,4,-8], and its sum is 6. The second part is [7], and its sum is 7. Since 6 < 7, i = 2 is not a valid split.

Thus, the number of valid splits in nums is 2.

Example 2:

Input: nums = [2,3,1,0]

Output: 2

Explanation:

There are two valid splits in nums:

- Split nums at index 1. Then, the first part is [2,3], and its sum is 5. The second part is [1,0], and its sum is 1. Since 5 >= 1, i = 1 is a valid split.

- Split nums at index 2. Then, the first part is [2,3,1], and its sum is 6. The second part is [0], and its sum is 0. Since 6 >= 0, i = 2 is a valid split.

 

Constraints:

  • 2 <= nums.length <= 105
  • -105 <= nums[i] <= 105

 

Solution:

class Solution {

    public int waysToSplitArray(int[] nums) {

        if (nums == null || nums.length <= 1 ) return 0;

        int sumSoFar = 0;

        int total = 0;

        int count = 0;

        for (int i = 0; i < nums.length; i++) {

            total += nums[i];

        }

 

        for (int i = 0; i < nums.length - 1; i++) {

            sumSoFar += nums[i];

            if (sumSoFar >= total-sumSoFar) {

                count += 1;

            }

        }

        return count;

    }

}

 

Test  cases:

[0] => 0

[1] => 0

[0,1] => 0

[1,0] => 1

[0,0,1] => 0

[0,1,0] => 1

[0,1,1] => 1

[1,0,0] => 2

[1,0,1] => 2

[1,1,0] => 2

[1,1,1] => 1

 

 

 

 

 

Thursday, December 7, 2023

 

Applying MicrosoftML rxLogisticRegression algorithm:  

 

While rxNeuralNet is a neural network implementation that helps with multi class classification and regression, Logistic Regression helps with binary outcomes. rxLogisticRegression is a binary and multiclass classification that classifies sentiments from feedback. This is a regular regression model where the variable that determines the category is dependent on one or more independent variables that have a logistic distribution.

 

This form of regression uses statistical measures, is highly flexible, takes any kind of input and supports different analytical tasks. This regression folds the effects of extreme values and evaluates several factors that affect a pair of outcomes.  Regression is very useful to calculate a linear relationship between a dependent and independent variable, and then use that relationship for prediction. Errors demonstrate elongated scatter plots in specific categories. Even when the errors come with different error details in the same category, they can be plotted with correlation. This technique is suitable for specific error categories from an account.   

 

Default detection rates can be boosted, and false positives can be reduced using real-time behavioral profiling as well as historical profiling. Big Data, commodity hardware and historical data going as far back as three years help with accuracy. This enables payment default detection to be almost as early as when it is committed. True real time processing implies stringent response times.

 

The algorithm for the least squares regression can be written as:   

 

1. Set the initial approximation    

 

2. For a set of successive increments or boosts each based on the preceding iterations, do   

 

3. Calculate the new residuals   

 

4. Find the line of search by aggregating and minimizing the residuals   

 

5. Perform the boost along the line of search   

 

6. Repeat 3,4,5 for each of 2.  

 

Conjugate gradient descent can be described with a given input matrix A, b, a starting value x, a number of iterations i-max and an error tolerance  epsilon < 1 in this way:

 

set I to 0        

set residual to b - Ax     

set search-direction to residual.    

And delta-new to the dot-product of residual-transposed.residual.    

Initialize delta-0 to delta-new    

while I < I-max and delta > epsilon^2 delta-0 do:     

    q = dot-product(A, search-direction)    

    alpha = delta-new / (search-direction-transposed. q)     

    x = x + alpha.search-direction    

    If I is divisible by 50     

        r = b - Ax     

    else     

        r = r - alpha.q     

    delta-old = delta-new    

    delta-new = dot-product(residual-transposed,residual)    

    Beta = delta-new/delta-old    

    Search-direction = residual + Beta. Search-direction    

    I = I + 1 

 

Sample application:  

#! /bin/python  
import numpy
import pandas
from microsoftml import rx_logistic_regression, rx_predict
from revoscalepy.etl.RxDataStep import rx_data_step
from microsoftml.datasets.datasets import get_dataset
infert = get_dataset("infert")

import sklearn
if sklearn.__version__ < "0.18":
    from sklearn.cross_validation import train_test_split
else:
    from sklearn.model_selection import train_test_split

infertdf = infert.as_df()
infertdf["isCase"] = infertdf.case == 1
data_train, data_test, y_train, y_test = train_test_split(infertdf, infertdf.isCase)

model = rx_logistic_regression(
    formula=" isCase ~ age + parity + education + spontaneous + induced ",
    data=data_train)
print(model.coef_)   

# RuntimeError: The type (RxTextData) for file is not supported.
score_ds = rx_predict(model, data=data_test,
                     extra_vars_to_write=["isCase", "Score"])                    

# Print the first five rows
print(rx_data_step(score_ds, number_rows_read=5))