theme | _class | paginate | backgroundColor | footer | marp |
---|---|---|---|---|---|
gaia |
lead |
true |
Computational Thinking and Social Science | :copyright: Matti Nelimarkka | 2023 | Sage Publishing |
true |
- Summarise the benefits of using functions.
- Create functions for specific needs.
- Summarise the benefits of using libraries.
- Know how to search the libraries available to solve specific problems.
- Describe how to use a library by working with its documentation.
- Explain why code management is important for scientific software development.
- List the important good practices for software development.
A function takes input variables, executes code by subjecting them to specific operations, and produces an output.
Function can be called from other code to execute it on the inputs and use the produced output.
Functions can be used for
- dividing the problem for simpler sub-problems
- abstracting common repetitive tasks into helper functions
- Code exercise: 8.1-8.5
- Libraries allow benefitting from other peoples’ work and put your effort into the actual problem.
- Libraries provide an application programming interface (API), which defines how the library can be used.
- An API comes with some documentation as well.
degree
Degree and Degree Distribution for Vertices
The degree of a vertex is its most basic structural property,the number of its adjacent edges.
Usage
degree(
graph,
v = V(graph),
mode = c(“all”, “out”, “in”, “total”),
loops = TRUE,
normalized = FALSE
)
Arguments
graph The graph to analyse.
1.10.1. Classification
DecisionTreeClassifier is a class capable of performing multi-class classification on a dataset.
As with other classifiers, DecisionTreeClassifier takes as input two arrays: an array X,
sparse or dense, of size [n_samples, n_features] holding the training samples,
and an array Y of integer values, size [n_samples], holding the class labels
for the training samples:
from sklearn import tree
X = [[0, 0], [1, 1]]
Y = [0, 1]
clf = tree.DecisionTreeClassifier()
clf = clf.fit(X, Y)
After being fitted, the model can be used to predict the class of samples:
clf.predict([[2., 2.]])
- Code exercise 8.6-8.8
- Treat code with respect, it is a vital tool for doing science.
- Leaving the code in such a shape that someone else – or ‘future you’, returning to it later – can read through it and understand what it does and the intended output.
Clarity and coding style
- Unclear variable names and other identifiers make it considerably harder to understand what the software does.
- Up to 70% of code is identifiers
- Write full words
- Conceptual link clear on the identifier
- Formulate consistently: empty space has a meaning
- Bad code smells!
- Lengthy code
- Shotgun surgery
- The Swiss army knife
- Copy-paste
Collaborative approaches
- Pair programming
- Code review
It is difficult to scope what the software should and should not do.
- Feature creep
- Extensive innovations
- Scheduling issues
- What are the components of a function?
- What are the two use cases for functions?
- Can a function have more than one output value?
- Why are libraries of help in software development?
- Can the degree function addressed in Example 8.2 count both in- and out-degree values?
- Can the degree function count the degree for only the selected nodes?
- Why is code maintenance important for computational social science?
- How does collaborative code development both improve and create challenges for code writing?
- What is a feature creep?
- What are some examples of bad code smell?