AlderAutomation

Uni Blog Week 04

Last updated: 25 minutes ago

Intro

I am sick this week, so it has been harder to pay attention and to function correctly, but we got through. This week was far more interesting than last week... mostly because of OS course and its C programming.

Project Management (Monday Morning)

Lecture

Very little lecture today. Gave instructions for a new assignment and then had us do a quiz that I had forgotten about and therefore was not ready for. Good thing, it's an open book class; I wound up getting 82% on that one. I am happy with that considering I did not prep for it.

Assignments

I got my Assignment 2 marks back: 100%

New assignment 3 is a month long-group project where we must pitch an idea to improve the university with a 100,000,000$ budget. The groups were forcibly assigned, which is probably good for me since I don't know anyone here yet. I have not heard from the group yet, but I have created a Discord server for us and sent out the invite link for it. I will wait. I am thinking that I will pitch the idea of a parking garage to the group. We have such limited parking at this Uni, and we share that parking with the city's arena. It gets full fast.

Operating Systems (Monday Afternoon)

Lecture

This week is all about system calls and processes. Its fascinating information but the professor is boring and I keep nodding off; It doesn't help that I am feeling under the weather. He mentioned linked lists, so I am going to try and build one in C. I also want to rebuild Conways Game of Life into C and Raylib. I have done it before in C++ and SFML. But I am still trying to finish my pong game.

Assignments

Assignment 2 asks about forking processes and how a program behaves based on those forked processes. Also asks about pipes and communicating between processes. I did the assingment and it was fascinating to see how forking worked with the parents and children, like a little logic puzzle. Piping pretty cool too, being able to tell processes to communicate with each other instead of making an intermediary file or some other programming voodoo. I'll post the questions below:

Question 1: Considering the program below, explain what the output will be at LINE 15:

    pid_t pid;
    pid = fork();

    if (pid == 0) { /* child process */
		printf("start child\n");
        value += 15;
		printf("CHILD: Value =  %d\n", value); 
		printf("end child\n");
        return 0;
    }
    else if (pid > 0) { /* parent process */
		printf("start Parent\n");
        wait(NULL);
        printf("PARENT: value = %d\n", value); /* LINE 15 */
		printf("end parent\n"); 
        return 0;

Question 2A: Consider the following two programs that use the fork() system calls, show the outputs of each program:

    if (fork() && fork())
        fork();

    printf("Hello\n");

    return 0; 

Question 2B:

    if (fork() > 0) {
        fork();
        printf("%s %d\n", "Hello", getpid());
    }

    printf("%s %d\n", "Hello again", getpid());

Question 3: Consider the following program in which partial sums of a given array are calculated concurrently by two processes, i.e., the child process and the parent process. Modify the program by adding a pipe so that the partial sum calculated by the child process is communicated to the parent process using this pipe. The parent process should be able to read from the pipe, add this partial sum calculation to its own partial sum calculation, and consequently calculate the total sum of all the integer elements of the array.

    int a[10] = {5, 4, 3, 0, 1, 4, 2, 6, 14, -3};
    int fd[2];
    pid_t pid;
    int sum = 0;
    int start;
    int end;

    pid = fork(); // fork a child process

    if (pid < 0) {
        fprintf(stderr, "Fork failed");
        return 1;
    }

    if (pid == 0) {
        // This is a Child process
        start = 0;
        end = (sizeof(a) / sizeof(a[0])) / 2;
    }
    else {
        // This is a parent process
        start = (sizeof(a) / sizeof(a[0])) / 2;
        end = sizeof(a) / sizeof(a[0]);
    }

    // Both the child and parent processes execute this portion
    for (int i = start; i < end; i++) {
        sum = sum + a[i];
    }

    printf("Partial Sum is %d\n", sum);

    return 0;

Data Communications (Tuesday Afternoon)

Lecture

Another quiz. The professor is going over chapter two of the textbook. Which is all about different signals; fiberglass, satellite, coaxial, etc. I need to hunker down and really work on this subject. This guy's quizzes are horrible.

Assignments

Another assignment that was pulled directly from the textbook.

Extreme Programming (Thursday Afternoon)

Lecture

Wound up skipping this class, was so damned sick. But I got the slides and the in-class activities. The lecture talks quite a bit about Hadoop and how it can be used as the shuffle process in mapreduce. Hadoop talks directly to python using stdin and stdout and can also run python executables directly. The lecture did not give any instructions or examples of Hadoop.

Also, I don't see why this course has to be done in Python. I think I am going to attempt some of these assignments in C. I'll let you know how that goes, if it goes.

Assignments

There were two in class assignments, neither to do with Hadoop (dafuq). The two assignments are just one assignment, I have no idea why they got separated. But it covers a set of transactions and goes through apriori and association rules. Here is the code:

from mlxtend.frequent_patterns import association_rules

import pandas as pd
from mlxtend.preprocessing import TransactionEncoder

transactions = [
    ['bread', 'milk', 'eggs'],
    ['bread', 'diapers', 'beer', 'eggs'],
    ['milk', 'diapers', 'beer'],
    ['bread', 'milk', 'diapers', 'beer'],
    ['bread', 'milk', 'diapers']
]

te = TransactionEncoder()
encoded = te.fit(transactions).transform(transactions)
df = pd.DataFrame(encoded, columns=te.columns_)
print(df)



print() 

from mlxtend.frequent_patterns import apriori

frequent = apriori(
    df,
    min_support=0.40,
    use_colnames=True
)
print(frequent.sort_values('support', ascending=False))


print()

rules = association_rules(
    frequent,
    metric='confidence',
    min_threshold=0.60
)

print(
    rules[['antecedents', 'consequents',
           'support', 'confidence', 'lift']]
    .sort_values('lift', ascending=False)
)

Conclusion

Losing two whole days to being sick and a third to a holiday really makes this week feel short. And I feel like I have no time for the assignments this week.

References

None this week.

If you want me to elaborate on anything, please message me on Discord, Mastodon, X, or email me. I’ll be happy to go into more detail one-on-one or to create more posts.

noaibadge

#blog #university