Friday, 17 March 2023

2.5% AQL: How it works - with Python Code



I will take a case study and then go through it taking two approaches.

Case: 

A vendor has offered 671 sarees for inspection, some of which are defective. 

a. How many sarees need to be inspected for a 2.5% AQL level

b. What is 2.5% AQL level

c. Suppose I took a sample of 26 sarees and 15 of them are defective, should I reject the whole lot

========
Solution 1. Using Hypothesis Testing Approach
========

To determine whether you should reject the whole lot of sarees, you need to conduct a hypothesis test using the sample data you have collected.

Here is how you can approach it:

1. Define the null and alternative hypothesis:

Null Hypothesis ( H0):  The proportion of defective sarees in the entire lot is equal to or less than a specified value p0.

Alternative Hypothesis ( Ha): The proportion of defective sarees in the entire lot is greater than p0. 

2. Set the significant level of the test. This is probability of rejecting the null hypothesis when it is actually true. Lets say you choose a significance level of 0.05.

3. Calculate the test statistic. For this situation, you can use a one-tailed Z -test, for proportions, the formula is 

z = (phat-p0)/sqrt(p0(1-p0)/n)

Where phat is the sample proportion of defective marbles, n is the sample size, and sqrt() denotes the square root function.

Plugging in the values from you sample, you get:

z = (15/26-p0)/sqrt(p0(1-p0)/26)

4. Determine the critical value or p-value. critical value can be found from a z -table for your chosen significance level. 

Alternatively, you can use p-value approach, which is to find the probability of getting a test statistic as extreme or more extreme than the observed one, assuming the null hypothesis is true. 

5. Decide. If the test statistic exceeds the critical value, or p-value is less than the significance level, you reject the null hypothesis and conclude that the proportion of defective sarees in the entire lot is greater than p0, else you fail to reject the null hypothesis.

Assuming that p0 = 0.05 and alpha = 0.05, then test statistic will be 

z = (15/26-0.05)/sqrt(0.05(1-0.05)/26) = 3.20

critical value for alpha 0.05 is 1.645, as 3.20 is more than that we reject the null hypothesis and conclude that the proportion of defective sarees in the entire lot is greater than 0.05. Therefore you should reject the whole lot of sarees.

You can use the following python code to achieve it. Here it is assumed that defective rate is max 2.5%, instead of 0.05 as above

============================
import statsmodels.stats.proportion as smprop

# Lot size
N = 671

# Number of defective marbles in the sample
defectives = 15

# Calculate the sample proportion of defectives
p_sample = defectives / N

# Null hypothesis: p <= 0.025 (defective rate is at most 2.5%)
# Alternative hypothesis: p > 0.025 (defective rate is higher than 2.5%)

# Perform one-tailed z-test with alpha = 0.05
z_score, p_value = smprop.proportions_ztest(defectives, N, value=0.025, alternative='larger')
print("z-score:", z_score)
print("p-value:", p_value)

if p_value <= 0.05:
    print("Reject null hypothesis")
else:
    print("Fail to reject null hypothesis")
=====================================



n this code, we first calculate the sample proportion of defectives by dividing the number of defective marbles by the lot size. We then set up the null and alternative hypotheses as before, and perform a one-tailed z-test with the proportions_ztest() function from the statsmodels.stats.proportion module. The proportions_ztest() function takes the following arguments:

count: the number of successes (defective marbles) in the sample.
nobs: the sample size (lot size).
value: the hypothesized proportion under the null hypothesis (which was 2.5% in this case).
alternative: the alternative hypothesis, which is 'larger' in this case since we are testing for a higher defective rate.
The proportions_ztest() function returns the z-score and p-value of the test. We compare the p-value to the significance level (alpha = 0.05) and make a decision to either reject or fail to reject the null hypothesis.

When you run this code, it will output the z-score and p-value of the test, and the decision to either reject or fail to reject the null hypothesis.



You can achieve the same assuming binomial distribution

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

import scipy.stats as stats

# Lot size
N = 671

# Null hypothesis: p <= 0.025 (defective rate is at most 2.5%)
# Alternative hypothesis: p > 0.025 (defective rate is higher than 2.5%)

# Number of defective marbles in the sample
defectives = 15

# Perform one-tailed binomial test with alpha = 0.05
p_value = stats.binom_test(defectives, n=N, p=0.025, alternative='greater')
print("p-value:", p_value)

if p_value <= 0.05:
    print("Reject null hypothesis")
else:
    print("Fail to reject null hypothesis")

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

The Jupyter code is:






In this code, the null hypothesis is that the defective rate p is at most 2.5% (i.e., p <= 0.025), and the alternative hypothesis is that p is higher than 2.5% (i.e., p > 0.025). We perform a one-tailed binomial test with the binom_test() function from the scipy.stats module, with the following arguments:

defectives: the number of defective marbles in the sample (which was 15 in this case).
n: the lot size (which was 671 in this case).
p: the hypothesized defective rate under the null hypothesis (which was 2.5% in this case).
alternative: the alternative hypothesis, which is 'greater' in this case since we are testing for a higher defective rate.
The binom_test() function returns the p-value of the test. We compare the p-value to the significance level (alpha = 0.05) and make a decision to either reject or fail to reject the null hypothesis.

When you run this code, it will output the p-value of the test and the decision to either reject or fail to reject the null hypothesis.


AQL Approach

Yes, you can use the AQL (Acceptable Quality Level) approach to solve this problem. AQL is a commonly used sampling plan in quality control that specifies the maximum acceptable percentage of defects in a sample. The AQL value is expressed as a percentage, and it represents the level of quality that is deemed acceptable by the customer or the manufacturer.

To use the AQL approach, you need to determine the sample size and the maximum allowable number of defects based on the AQL value and the lot size. The formula for calculating the sample size is:

n = (Zα/2)2 * p * (1-p) / d2

where Zα/2 is the critical value of the standard normal distribution corresponding to the desired level of confidence (e.g., Zα/2 = 1.96 for a 95% confidence level), p is the expected proportion of defects in the lot, d is the maximum allowable difference between the sample proportion and the lot proportion (i.e., the AQL value), and n is the sample size.

For this problem, let's assume that the AQL value is 2.5%, and we want to be 95% confident that the sample proportion is within 2.5% of the lot proportion. We can set p = 15/671, the proportion of defective marbles in the lot based on the sample, and d = 2.5% = 0.025. The lot size is already given as 671.

Using the formula, we get:

n = (1.96)2 * (15/671) * (1 - 15/671) / (0.025)2 ≈ 106

This means that we need to randomly sample 106 sarees from the lot to determine whether the lot meets the AQL requirement of 2.5% defects. If the number of defective sareesin the sample is less than or equal to 3 (i.e., 2.5% of 106), we accept the lot. If it is greater than 3, we reject the lot.

In this case, the sample has 15 defective sarees, which is greater than 3, so we would reject the lot based on the AQL approach as well.

You can use the following python code to achieve it. Here it is assumed that defective rate is max 2.5%, instead of 0.05 as above

To make the Z value dynamic depending on the desired confidence level, you can modify the sample_size function to accept a parameter for the confidence level, and then calculate Z using the scipy.stats.norm.ppf() function, which returns the critical value of the standard normal distribution corresponding to a given percentile (i.e., confidence level).

========================
import math
from scipy.stats import norm

# Lot size
N = 671

# Sample size formula
def sample_size(AQL, p, alpha):
    Z = norm.ppf(1 - alpha/2) # Critical value for two-tailed test
    d = AQL # Maximum allowable difference
    n = ((Z**2) * p * (1 - p)) / (d**2)
    return math.ceil(n)

# Calculate sample size for AQL = 2.5%, p = 15/671, and alpha = 0.05 (95% confidence level)
n = sample_size(0.025, 15/671, 0.05)
print("Sample size:", n)

# Number of defective marbles in the sample
defectives = 15

# Check if the lot meets the AQL requirement at alpha = 0.05
AQL_defectives = math.ceil(n * 0.025) # Maximum allowable defects based on AQL
if defectives <= AQL_defectives:
    print("Lot accepted")
else:
    print("Lot rejected")
    
# Check if the lot meets the AQL requirement at alpha = 0.01 (99% confidence level)
n = sample_size(0.025, 15/671, 0.01)
print("Sample size:", n)
AQL_defectives = math.ceil(n * 0.025)
if defectives <= AQL_defectives:
    print("Lot accepted")
else:
    print("Lot rejected")
=========================================




In this code, the alpha parameter represents the significance level (1 - confidence level), which is used to calculate the critical value of Z. The norm.ppf() function takes a percentile (in this case, 1 - alpha/2 for a two-tailed test) and returns the corresponding critical value of the standard normal distribution.

When you run this code, it will output the sample size and the lot acceptance/rejection decision for both a 95% confidence level (alpha = 0.05) and a 99% confidence level (alpha = 0.01). The Z value will be different for each confidence level, and will be calculated using the norm.ppf() function.

Sunday, 15 May 2022

The Rich Tapestry of Indian Sarees: A State-wise Exploration




The Indian saree is a timeless and iconic garment that has been a part of Indian culture for centuries. With its elegant drape and intricate designs, it represents the diverse traditions and craftsmanship of the country. The modern wearing style of saree was invented in 1862 by Rani Gyanodanandini Tagore, wife of Satyandranath Tagore, who was the elder brother of Rabindranath Tagore. Each state in India has its unique style of saree, with distinct patterns, borders, and fabrics. In this article, we delve into the rich tapestry of Indian sarees, exploring the variations across different states.

Kerala:
In Kerala, the saree is known as "Pudva." It typically features a simple yet elegant design with a border called "Kara." The body or ground of the saree is referred to as "Udal." The outer end-piece is called "Mundani" or "Anchalam," while the inner end-piece is known as "Ullattam." The saree is often adorned with a selvedge called "Vakka" and an end fringe called "Allukk." The parting-stripe of warp without weft is left plain, and the saree is folded in a style known as "Madak."

Karnataka:
Karnataka embraces the saree in various forms, including "Seere" and "Bond." The border, known as "Kinar," "Anchu," or "Patta," adds a touch of elegance to the saree. The body or ground is called "Nadamu" or "Maidan." The outer end-piece, referred to as "Seregu" or "Pallav," is intricately designed. The inner end-piece, called "Lopala Kongu," complements the overall look. The saree is finished with a selvedge called "Ginta Javana," "Jamada," or "Jawla." The end fringe is known as "Baddi," "Badi Athari," "Badhaggi," or "Kante Thojhalar." The saree fold style in Karnataka is called "Chotto Attri," "Potta Athari," "Badige," or "Galinge."

Goa:
Goa celebrates its saree heritage with names like "Lugda," "Kapad," and "Sado." The border, known as "Kath," adds a distinctive touch. The body or ground of the saree is called "Aang." The outer and inner end-pieces are referred to as "Bhailo," "Pallov," "Podar," and "Bheetolo Pallov," respectively. The saree is adorned with a selvedge called "Kath," and the end fringe is known as "Gone." The parting-stripe of warp without weft is called "Dassi," and the saree is folded in the "Ghadi" style.

Maharashtra:
Maharashtra boasts a range of sarees, including "Baan" and "Lugda." The border, known as "Ghadi," "Mad," "Kinar," or "Garbh," is intricately designed. The body or ground of the saree is called "Dal" or "Garbh." The saree features a distinct end-piece called "Padar" or "Patti." The inner end-piece is referred to as "Dhungan Patti." The saree is adorned with a selvedge called "Jeeb" or "Nakhi." The end fringe is known as "Punchra." The finishing touch is given with a decorative element called "Dassi" or "Dasta." The Maharashtra style of folding the saree is known as "Ghadi."

Gujarat:
Gujarat is renowned for its vibrant sarees like "Lugda" and "Sadlo." The border, known as "Kor," "Phumro," or "Dhaburao," features intricate patterns and designs. The body or ground of the saree is called "Pate," "Libhai," or "Bhoomi." The saree often showcases a beautiful pallav or outer end-piece called "Saur," "Chheda," or "Pallav." The selvedge is referred to as "Chilla," while the end fringe is called "Kantho," "Kanar," "Baid," or "Dhari." The saree is folded with finesse in a style known as "Fumka." The parting-stripe of warp without weft is called "Chiran."

Madhya Pradesh and Chhattisgarh:
Madhya Pradesh and Chhattisgarh offer a variety of sarees, including "Jote," "Lugda," and "Pata." The border, known as "Kinar" or "Dhadi," is often intricately woven. The body or ground is called "Peta," "Deh," "Zamin," "Dharti," or "Howda." The saree features a unique end-piece called "Pallavan," "Patta," "Munh," "Anchi," or "Jhela." A decorative element called "Kanihai Patti" adds charm to the saree. The selvedge is referred to as "Dun" or "Dohra Patti." The end fringe is known as "Phunchra," and the saree fold is called "Chir" or "Dhadi."

Uttar Pradesh:
Uttar Pradesh embraces the saree in various styles like "Dhoti," "Lugdi," "Lugga," and "Sari." The border, known as "Kinar" or "Bel," is intricately woven. The body or ground is called "Pote" or "Zameen." The saree showcases a beautiful pallu or outer end-piece called "Palloo," "Palla," or "Anchal." The selvedge is referred to as "Tala" or "Deodhi Ke Baad." The finishing touch is given with a decorative element called "Koria" or "Berai." The saree features a delicate end fringe known as "Jhalar." The saree fold styles in Uttar Pradesh include "Cheer" and "Ghadi" or "Tehi."

Bihar and Jharkhand:
Bihar and Jharkhand have their own distinct styles of sarees that showcase the cultural richness of the region. The sarees in these states are known by names like "Dhoti," "Luga," and "Langa." The border, called "Paar" or "Kinar," adds a touch of elegance to the saree. The body or ground is referred to as "Zameen," "Lapate," or "Hauz." The saree features a beautiful end-piece known as the "Aanchal" or "Mukpat." A unique decorative element called "Gajnautha" is often incorporated into the design. The selvedge is known as "Kor," and the end fringe is called "Dassi" or "Fudna." The saree is folded in a style known as "Cheela," while the parting-stripe of warp without weft is referred to as "Dhadi."

West Bengal:
West Bengal, known for its rich artistic heritage, offers a diverse range of sarees that capture the essence of the region. The saree in West Bengal is often referred to as "Bhaaj." The border, called "Paar" or "Payrey," showcases intricate patterns and designs. The body or ground of the saree is referred to as "Jameen," "Gaa," "Khol," or "Pota." The outer end-piece, known as "Uni Aanchol" or "Aanchala," adds a touch of grace. The inner end-piece is referred to as "Thol Aanchal," "Kolod," or "Kol." The saree is often embellished with decorative elements like "Aal," "Aanthi," "Mulkandi," or "Aangot." The saree features a distinctive end fringe called "Chhela" or "Dosi." In West Bengal, the saree is often folded in the traditional style of "Bhaaj" or "Guti Bhaaj."

The diverse range of Indian sarees reflects the rich cultural heritage and craftsmanship of each state. From the simple elegance of Kerala's "Pudva" to the vibrant patterns of Gujarat's "Lugda," each saree tells a unique story. Exploring the different styles, borders, body/ground, end-pieces, selvedges, and folds of sarees across India offers a fascinating glimpse into the country's rich textile traditions. Whether it's the traditional weaves of Maharashtra or the intricate designs of Karnataka, Indian sarees continue to captivate with their timeless beauty and cultural significance.

Friday, 6 May 2022

Difference between Kanjivaram and Dharmavaram sarees



Kanjivarams for commercial use are mainly made in Salem and Dharmavaram clusters. 
In Dharmavaram, zari is used both/either in warp and weft, usually mixed with Resham. In Salem, Resham ( Silk is used in warp and weft). In salem, brocades are created using extra thread figuring. Also Kuttu pallu is used in Dharmavaram in most of the sarees for creating contrast colors in pallu. In salem, tie-and-dye  is used for the same. Also in Salem Butas are used in the sarees, as compared to Dharmavarams that use brocades. 

In Kanjivaram, stiffening is done during polishing as compared to Dharmavaram where softening is done. 

Dharmavaram sarees are cheaper than the Kanjivaram, because they use zari in warp as compared to Kanjivaram, that use pure silk. 

Here is a list of other differences: 

Weaving Technique: The weaving technique used for Kanjivaram sarees is known as "korvai," which involves separately weaving the body and border of the saree and then interlocking them. In contrast, Dharmavaram sarees are woven in a "pit loom" technique, where the entire saree is woven as a single piece, including the body, border, and pallu (the loose end of the saree).

Motifs and Designs: Kanjivaram sarees are known for their rich and intricate designs, often featuring traditional South Indian motifs such as temple borders, checks, and floral patterns. Dharmavaram sarees, on the other hand, typically showcase broader borders with contrasting colors and intricate designs inspired by nature, mythology, and local culture.

Pallu Design: The pallu of a Kanjivaram saree usually features elaborate designs and motifs that complement the overall look of the saree. In contrast, Dharmavaram sarees often have a plain or minimally designed pallu, allowing the focus to be on the border and body of the saree.

Color Palette: Kanjivaram sarees are known for their vibrant and contrasting color combinations, with a wide range of options available. Dharmavaram sarees, on the other hand, often feature more subtle and harmonious color schemes.

Both Kanjivaram and Dharmavaram sarees are highly regarded and cherished for their beauty, craftsmanship, and cultural significance. Whether it's the weaving technique, designs, or regional influences, these sarees showcase the artistic diversity and heritage of South India.

Difference in Motifs 

The motifs used in Kanjivaram and Dharmavaram sarees differ in terms of their design elements and inspirations. Here are the general characteristics of motifs found in both saree types:

Kanjivaram Saree Motifs:

Temple Borders: Kanjivaram sarees are renowned for their temple border motifs, which draw inspiration from the architectural designs of South Indian temples. These motifs often feature intricate depictions of temple carvings, deities, peacocks, elephants, and other elements associated with temple art and culture.

Checks and Stripes: Another common motif in Kanjivaram sarees is the use of checks and stripes. These patterns can be either small or large and are typically created using contrasting colors. The checks and stripes add a distinctive visual appeal to the saree.

Floral Patterns: Floral motifs are often seen in Kanjivaram  sarees, representing natural elements and incorporating various flowers like lotus, jasmine, and roses. These floral designs are intricately woven into the saree to create an elegant and timeless look.

Peacock Motifs: Peacocks hold a special place in South Indian culture, and their motifs are frequently used in Kanjeevaram sarees. Peacock-inspired designs are woven into the pallu or border of the saree, showcasing the grace and beauty of these majestic birds.

Dharmavaram Saree Motifs:

Nature-inspired Motifs: Dharmavaram sarees often feature motifs inspired by nature, such as flowers, leaves, vines, and trees. These motifs are intricately woven into the saree to depict the beauty and abundance of the natural world.

Mythological Motifs: Dharmavaram sarees also draw inspiration from Hindu mythology and folklore. Motifs representing gods, goddesses, and mythological characters are commonly seen, symbolizing devotion and cultural heritage.

Peacock and Swan Motifs: Similar to Kanjivaram sarees, Dharmavaram sarees often incorporate peacock and swan motifs. These motifs are believed to symbolize grace, purity, and beauty, and they add an element of charm to the overall design.

Geometric Patterns: Dharmavaram sarees occasionally feature geometric patterns, such as squares, diamonds, and triangles, adding a contemporary touch to the traditional design. These geometric motifs are often combined with other elements to create a visually striking composition.

Buy my books at Amazon.com

Polishing in Kanjivaram Sarees



Polishing involves application of gum and winding the saree onto cloth rolls. The aim is to put the stiffness in the fabric. 

Polishing in Salem Kanjivaram sarees is done only for Powerloom sarees after they are made. The Gaund ( Gum ) is applied by hand after the saree is made before it is wound on the square planks. Then it is made to dry in the sunlight for about six hours. 

For handloom sarees, it is applied while it is made. After every one feet or more of weaving. The gum ( Pasai) is applied. 

In Dharmavaram, instead of stiffening, the softening is done, as it is mostly zari. They also use shampoo to make it shining. 

In Handloom fabrics in Dharmavaram, they use bisleri water to make it shining. 

Total Pageviews