text:
# “Guess the Number” game in Python

I have been using Python 3 to learn programming, and this is a very basic task, but I want to gain good programming patterns/habits at the very beginning.

The program will first randomly generate a number unknown to the user. The user needs to guess what that number is. The program interacts with the user.

import random
randomNumber = random.randrange(0,100)
print("Random number has been generated")
guessed = False
while guessed==False:
userInput = int(input("Your guess pleas: "))
if userInput==randomNumber:
guessed = True
print("Well done!")
elif userInput>100:
print("Our guess range is between 0 and 100, please try a bit lower")
elif userInput<0:
print("Our guess range is between 0 and 100, please try a bit higher")
elif userInput>randomNumber:
print("Try one more time, a bit lower")
elif userInput < randomNumber:
print("Try one more time, a bit higher")

print("End of program")

• "Your guess pleas: ": you're missing an e in please. – 301_Moved_Permanently Jul 1 '16 at 8:38

PEP8 specifies that variables should be named like functions, using _underscores_ over mixedCase:

randomNumber -> random_number

userInput -> user_input

## Use chained comparisons

Building on Graipher's point, I would negate the condition and take advantage of Python's chained comparison operators:

elif not 0 <= user_input <= 100:
print("Our guess range is between 0 and 100, please try again")

2 sets of strings in your code are very similar to each other. The conditional branches that bring you there are also similar and compare against the same variables.

In those cases, you can combine the branch conditions and strings together and branch only at the point when the strings differ, minimizing the duplication between strings. str.format() or the % operator along with conditional expressions are your friends here:

elif not 0 <= user_input <= 100:    # Combines 2 branches into 1
print("Our guess range is between 0 and 100, please try a bit {}."
#                                                             ^
# The strings only starts to differ based on the condition here
.format("higher" if user_input < 0 else "lower"))

Although you were only referring to Python 3 for this exercise, it's a good idea to add compatibility for Python 2 for real applications.

Simply redefining input() is enough in this simple program:

if sys.version_info[0] < 3:
input = raw_input

For more complicated programs, I suggest you look into six.

## Group code into functions

This is helpful even for a small program since it prevents too many variables from polluting the module scope and allows your module to be importable from another program. It's also easier to read and extend later on.

(In the example below, you can easily add a range_min and range_max parameter to start_guess() to easily tune the range of numbers to guess from)

## Use is False instead of == False if necessary

You should generally avoid direct comparisons to a Boolean and just use not <variable> as Toastrackenigma said if you know the possible values of the variable.

However, in cases where the variable value can also be an int, which is probably a sign of bad programming practice anyway, it's better to use is False over == False because 0 == False.

(This is not needed in the sample below)

# Updated code with mine and everyone's suggestions:

import random
import sys

# Compatibility with Python 2
if sys.version_info[0] < 3:
input = raw_input

def start_guess():
random_number = random.randrange(0, 101)
print("Random number has been generated.")

while True:
try:
except ValueError:
continue
if user_input == random_number:
print("Well done!")
break
elif not 0 <= user_input <= 100:    # If it's not between 0 to 100
print("Our guess range is between 0 and 100, please try a bit {}."
# User_input at this point must be outside the range
# so if it's not below the min, it's definitely above the max
.format("higher" if user_input < 0 else "lower"))
else:
print("Try one more time, a bit {}."
# User_input at this point must be inside the range
# so if it's not below the random_number, it's definitely above it
.format("higher" if user_input < random_number else "lower"))

if __name__ == '__main__':
start_guess()
print("End of program.")

I would probably combine these two if clauses:

elif userInput>100:
print("Our guess range is between 0 and 100, please try a bit lower")
elif userInput<0:
print("Our guess range is between 0 and 100, please try a bit higher")

To:

elif user_input > 100 or user_input < 0:
print("Our guess range is between 0 and 100, please try again")

Trusting that the user is clever enough to realise that if he entered 1000 (which is still visible in the line just above this output), that he is too high for range(1,101).

Incidentally, there may be a small bug in your program:

random.randrange(1,100)

will never generate 100, just like range(1,100) will only give you the numbers from 1 to 99, inclusive. But you also allow the user to guess 0 or 100.

Use either of these two:

random.randrange(0,101)
random.randint(0,100)

The latter actually does return an integer N, such that a <= N <= b

Your program will crash if the user enters any non-number. Better use something like:

while True:
try:
except ValueError:
continue
if user_input == random_number:
print("You win")
break
elif user_input < 0 or user_input > 100:
print("Our guess range is between 0 and 100, please try again")
elif user_input < random_number:
# Notify user
elif user_input > random_number:
# Notify user

Which will ask the user until a valid number is supplied. You can also put all the other checking code in there as well.

Always do yourself a favor and use this convention:

if __name__ == '__main__'

convention from the beginning. This prevents confusing behaviour, such as when you want to use a function that's further down in your code. It also helps to structure your code better into functions.

• We don't normally use comparison operators for booleans like you do in

while guessed==False :

while not guessed :

(same as the code that you have) or

while guessed :

(opposite to the code you have - runs while true)

The reason for this is that doing another comparison is simply an overkill. The statement is going to evaluate to a boolean anyway, so why not use the one that you already have, and invert if necessary? To check if something is true, comparison actually does nothing, and in this example negation (with not) is slightly faster and easier to read than what you have.

• Either: Put spaces around your all of your operators for readability, or stick to not using spaces around any of your operators - don't mix and match like you do in this program. Do note however that although it is good to be consistent, it is even better to stick with standards and simply put spaces around all of your operators.

## Comment

Your program seems to be based on good, solid principles, and has been (for the most part) nicely implemented.

• It's not a good recommendation to never put spaces around operator. It directly violates the official style guide PEP8 linked from the other answer. – janos Jul 1 '16 at 8:40
• @janos I was trying to say that OP should use consistent practices in their code, but also stick to standards and put spaces around their operators. I can definitely see how I didn't quite convey the latter, so I've added another sentence to clarify that. Thanks for pointing it out :) – Toastrackenigma Jul 1 '16 at 23:08


text:
# Anne M. Leggett

Anne Marie Leggett is an American mathematical logician. She is an associate professor emerita of mathematics at Loyola University Chicago.

Leggett is the editor-in-chief of the newsletter of the Association for Women in Mathematics.[1] With Bettye Anne Case, she is the editor of the book Complexities: Women in Mathematics (with Anne M. Leggett, Princeton University Press, 2005).[2]

## Education and career

Leggett did her undergraduate studies at Ohio State University, and completed her Ph.D. in 1973 at Yale University.[3] Her dissertation, Maximal ${\displaystyle \alpha }$-r.e. sets and their complements, was supervised by Manuel Lerman.[4]

She became a C. L. E. Moore instructor at the Massachusetts Institute of Technology in 1973,[5] and was also on the faculties of Western Illinois University and the University of Texas at Austin.[3] In 1982, she married another mathematician, Gerard McDonald (1946–2012), and in 1983, they both joined the Loyola Chicago faculty.[6]

## Recognition

Leggett was chosen to be part of the 2019 class of fellows of the Association for Women in Mathematics, "for extraordinary contributions in promoting opportunities for women in the mathematical sciences through AWM and as a teacher and scholar; for her amazing and steady work as editor of the AWM Newsletter since 1977; and for her invaluable leadership and guidance."[7]

## References

1. ^ Executive committee, Association for Women in Mathematics, retrieved 2018-10-08
2. ^ Reviews of Complexities: Women in Mathematics:
3. ^ a b "McDonald, Anne", Mathematics and Statistics, Loyola University Chicago, retrieved 2018-10-08
4. ^
5. ^ Moore Instructors at MIT from 1949, Massachusetts Institute of Technology Mathematics Department, retrieved 2018-10-08
6. ^ "In loving memory", Loyola Phoenix, September 2, 2012, retrieved 2018-10-08
7. ^ 2019 Class of AWM Fellows, Association for Women in Mathematics, retrieved 2018-10-07

format: plain


text:
Department of

# Mathematics

Seminar Calendar
for events the day of Monday, June 25, 2018.

.
events for the
events containing

Questions regarding events or the calendar should be directed to Tori Corkery.
       May 2018              June 2018              July 2018
Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa
1  2  3  4  5                   1  2    1  2  3  4  5  6  7
6  7  8  9 10 11 12    3  4  5  6  7  8  9    8  9 10 11 12 13 14
13 14 15 16 17 18 19   10 11 12 13 14 15 16   15 16 17 18 19 20 21
20 21 22 23 24 25 26   17 18 19 20 21 22 23   22 23 24 25 26 27 28
27 28 29 30 31         24 25 26 27 28 29 30   29 30 31

Monday, June 25, 2018

10:00 am in 245 Altgeld Hall,Monday, June 25, 2018

#### Chair Search – Q&A

###### Jeremy Tyson

Abstract: View the video of this Q&A Session at https://www.youtube.com/watch?v=hE4zD29Wrrc&feature=youtu.be


text:
# Is this deduction in normal form?

Definition: A deduction is in normal form if there is no formula which is a conclusion of an introduction rule and the main premise of the elimination rule of the same connective.

So, in a natural deduction system, one can normalize a proof that contains an introduction rule of a connective followed right after by the elimination rule of the same connective. Here, I have the opposite. First two elimination rules and then the introduction rule of the same connective.

By this definition, the above deduction is in normal form. But still, it can be reduced to a simpler deduction (the trivial A∧B). It seems correct to me, that we can reduce it to just the axiom $$A\wedge B$$. But how, since the structure of the deduction doesn't have a pair of rules that could be eliminated?

For whoever cannot see the image on the post, I'll give a description of the deduction depicted in it.

(1): $$A\wedge B\vdash A$$ (by conjunction elimination)

(2): $$A\wedge B\vdash B$$ (by conjunction elimination, again)

(3): $$A, B\vdash A\wedge B$$ (by conjunction introduction on (1) and (2))

• I'm not able to read the link. It is much easier for the "potential answerers" if you type in the formulas. Feb 4 '14 at 16:26
• You can download Latex symbols from the web for the symbols, used the tutorial of this site and last (without saving) edit a question/answer with the formula you need and copy them ... Feb 4 '14 at 16:56
• For the tutorial of this site, see the guideline Feb 4 '14 at 17:13
• I think that (3) is wrong; it must be like : $A, B \vdash A \land B$. If your tree is made by two branch: the first one ending with (1) and the second one with (2), and after them you use again (with $A$ and $B$ as premisses) $\land$-I, why you need it ? Of course, we must see what we have on top of (1) and (2), but if what you need is really $A \land B$ and you have already on branch (1), I think you can use that only... Feb 4 '14 at 17:57
• Now I read it - simply "cut" the right branch (for example) and avoid the "detour" from $A \land B$ to $A \land B$ through $A$. Feb 4 '14 at 20:21

By the Curry-Howard isomorphism, the deduction in question corresponds exactly to an $\eta$-reduction of $\lambda$-calculus.


text:
## Algebra 1

The relationship is a linear function because the graph increases by 92 units every time for every x-value Equation: Slope: $\frac{(y_{2}-y_{1})}{(x_{2}-x_{1})}$ $\frac{(1219-1127)}{(1-0)}$ $\frac{92}{1}$ slope=92 y-int: y=92x+b (substitute any x & y value from the table) 1311=92(2)+b 1311=184+b -184 -184 1127=b Equation: y=92x+1127


text:
# framebox does not work for lstlisting environment

I am looking a way to wrap something with a frame. I try different approaches but finally choose to use fancybox package and minipage (because I need to control the width of the frame). It works pretty good for text-only content

\usepackage{fancybox}

\begin{document}
\fbox{%
\begin{minipage}{\textwidth}
\textbf{Why we use negative angle in above calculate?}\newline
Since .... we have to ....
\end{minipage}
}
\end{document}

However, if we add any environment like lstlisting or verbatim, it doesn't work

  \fbox{%
\begin{minipage}{\textwidth}
\textbf{Why we use negative angle in above calculate?}\newline
Since .... we have to ....
\begin{lstlisting}
A = x+y;
B = x^2-2y;
\end{lstlisting}
\end{minipage}
}

Is that any way to make it work?

p.s. I have created a webpage for the user to type the latex stuff inside and whatever they type, I will like to wrap that with a framebox and generated a pdf with pdflatex. I cannot control what they type, they might type text, math, environment and/or mix all of those. So any better way to frame whatever the latex stuff inside?

-

This is because listings (including verbatim content) cannot be passed as arguments to other functions/macros (without care). Boxing the content first is okay though:

\documentclass{article}
\usepackage{listings}% http://ctan.org/pkg/listings
\newsavebox{\codebox}% For saving code
\begin{document}
\begin{lrbox}{\codebox}
\begin{lstlisting}
A = x+y;
B = x^2-2y;
\end{lstlisting}
\end{lrbox}

\noindent
\fbox{%
\begin{minipage}{\dimexpr\linewidth-2\fboxsep-2\fboxrule}
\textbf{Why we use negative angle in above calculate?}\newline
Since .... we have to .... \par
\usebox{\codebox}
\end{minipage}%
}
\end{document}

lrbox is an environment that takes one mandatory (box) argument which it will use to store the content in. I've made on called \codebox. Do this outside your \fbox and then use \usebox{\codebox} inside \fbox's argument.

Note the use of \noindent, occational % (see What is the use of percent signs (%) at the end of lines?) and a \dimexpr for the minipage size to avoid overfull \hbox warnings.

If you don't have control over what the user inserts and they could mix/match content, then you might be better off boxing everything and just \fbox-ing the output:

\documentclass{article}
\usepackage{listings}% http://ctan.org/pkg/listings
\newsavebox{\userinput}% For saving user input
\begin{document}
\begin{lrbox}{\userinput}
\begin{minipage}{\dimexpr\linewidth-2\fboxsep-2\fboxrule}
\textbf{Why we use negative angle in above calculate?}\newline
Since .... we have to ....

\begin{lstlisting}
A = x+y;
B = x^2-2y;
\end{lstlisting}
\end{minipage}
\end{lrbox}

\noindent
\fbox{\usebox{\userinput}}%
\end{document}

Of course, mdframed has no problem with this kind of thing, and might be a better option; it also allows for frame breaking across the page boundary:

\documentclass{article}
\usepackage{listings,mdframed}% http://ctan.org/pkg/{listings,mdframed}
\begin{document}
\begin{mdframed}
\textbf{Why we use negative angle in above calculate?}\newline
Since .... we have to ....

\begin{lstlisting}
A = x+y;
B = x^2-2y;
\end{lstlisting}
\end{mdframed}

\end{document}

See the mdframed documentation for more details on making things fancy.

-
 Hi Werner, thanks for the reply. I am wondering if this is the only way to make it work by using lrbox and with other stuffs like \par. I have a python script to generate the frame box, so whatever the user type, I just want to wrap it with a frame. But I cannot control what the user type, he may use listing or not or mix listing and other command. So any way to wrap whatever latex command, text, math and/or environments people typed? Thanks – user1285419 Feb 1 at 19:59 @user1285419: I've added two alternatives. – Werner Feb 1 at 20:06 Thanks Werner. It works – user1285419 Feb 1 at 22:38

The listings package provides in-built options for framing listings environments, either globally using (for example)

\lstset{frame=single}

or else locally using (for example)

\begin{lstlisting}[frame=single]

A complete MWE follows

\documentclass{article}

\usepackage{xcolor}
\usepackage{listings}

\lstset{frame=single}

\begin{document}

\begin{lstlisting}[frame=single]
A = x+y;
B = x^2-2y;
\end{lstlisting}

\begin{lstlisting}[backgroundcolor=\color{yellow!20}]
A = x+y;
B = x^2-2y;
\end{lstlisting}

\end{document}

-


text:
### 统计代写|python代考|Functions

Python是一种高级的、解释性的、通用的编程语言。它的设计理念强调代码的可读性，使用大量的缩进。

Python是动态类型的，并且是垃圾收集的。它支持多种编程范式，包括结构化（特别是程序化）、面向对象和函数式编程。由于其全面的标准库，它经常被描述为一种 “包含电池 “的语言。

statistics-lab™ 为您的留学生涯保驾护航 在代写python方面已经树立了自己的口碑, 保证靠谱, 高质且原创的统计Statistics代写服务。我们的专家在代写python代写方面经验极为丰富，各种代写python相关的作业也就用不着说。

• Statistical Inference 统计推断
• Statistical Computing 统计计算
• Advanced Probability Theory 高等概率论
• Advanced Mathematical Statistics 高等数理统计学
• (Generalized) Linear Models 广义线性模型
• Statistical Machine Learning 统计机器学习
• Longitudinal Data Analysis 纵向数据分析
• Foundations of Data Science 数据科学基础

## 统计代写|python代考|Putting Your Program into Its Own File

Up until this point, any time you wanted to accomplish a task, you have needed to type out entire programs to do the job. If you needed to do the same work again, you could type the entire program again or place it in a loop. However, loops are most useful when you are repeating the same thing, but writing the same loop repeatedly in different parts of your program with slightly modified values in each one is not a sane way to live your life.

Python has functions that enable you to gather sections of code into more convenient groupings that can be called on when you have a need for them.

In this chapter, you will learn how to create and use your own functions. You will be given guidelines to help facilitate your thinking about how to create and structure your programs to use functions. You will also learn to write your functions so that you can later interrogate them for information about how they behave and what you intend for them to do.

As the examples in this book get longer, typing the entire code block begins to be a burden. A single mistake causes you to retype in the entire block of code you are working on. Long before you’ve gotten to the point where you’ve got more than, say, 40 lines of code to type, you are unlikely to want to have to do it more than once.
You are probably already aware that programmers write programs that are saved as source code into files that can be opened, edited, and run without a great deal of work.

To reach this far more convenient state of affairs, from here on out you should type the programs you are using into the main codeEditor window, and save the examples from the book into a single folder from which you can reference them and run them. One suggestion for naming the folder could be “Learning Python, ” and then you could name the programs according to the chapters in which they appear.

## 统计代写|python代考|Grouping Code under a Name

When you invoke ch5. py with just the in_fridge function defined, you won’t see any output. However, the function will be defined, and it can be invoked from the interactive Python session that you’ve created.

To take advantage of the in_fridge function, though, you have to ensure that there is a dictionary called fridge with food names in it. In addition, you have to have a string in the name wanted_food. This string is how you can ask, using in_fridge, whether that food is available. Therefore, from the interactive session, you can do this to use the function:
$>>>$ fridge $=\left{\right.$ ‘apples’ $: 10$, ‘oranges’ $: 3$, ‘milk’ $\left.1 k^{\prime}\right}$
$>>$ wanted_food = ‘apples’
$>>$ in_fridge(l)
10
$>>$ wanted_food = ‘oranges’
$>>>$ in_fridge()
3
$>>>$ wanted_food = ‘milk’
$>>$ in_fridge(1)
2
This is more than just useful – it makes sense and it saves you work. This grouping of blocks of code under the cover of a single name means that you can now simplify your code, which in turn enables you to get more done more quickly. You can type less and worry less about making a mistake as well.

Functions are a core part of any modern programming language, and they are a key part of getting problems solved using Python.
Functions can be thought of as a question and answer process when you write them. When they are invoked, a question is often being asked of them: “how many,” “what time,” “does this exist?” “can this be changed?” and more. In response, functions will often return an answer – a value that will contain an answer, such as True, a sequence, a dictionary, or another type of data. In the absence of any of these, the answer returned is the special value None.
Even when a function is mainly being asked to just get something simple done, there is usually an implied question that you should know to look for. When a function has completed its task, the questions “Did it work?” or “How did it work out?” are usually part of how you invoke the function.

## 统计代写|python代考|Describing a Function in the Function

After you’ve chosen a name for your function, you should also add a description of the function. Python enables you to do this in a way that is simple and makes sense.

If you place a string as the first thing in a function, without referencing a name to the string, Python will store it in the function so you can reference it later. This is commonly called a docstring, which is short for documentation string.
Documentation in the context of a function is anything written that describes the part of the program (the function, in this case) that you’re looking at. It’s famously rare to find computer software that is well documented. However, the simplicity of the docstring feature in Python makes it so that, generally, much more information is available inside Python programs than in programs written in other languages that lack this friendly and helpful convention.
The text inside the docstring doesn’t necessarily have to obey the indentation rules that the rest of the source code does, because it’s only a string. Even though it may visually interrupt the indentation, it’s important to remember that, when you’ve finished typing in your docstring, the remainder of your functions must still be correctly indented.
def in_fridge (\rangle :
*”This is a function to see if the fridge has a food.
fridge has to be a dictionary defined outside of the function.
the food to be searched for is in the string wanted_food” *
try:
count = fridge[wanted_food]
def in_fridge ():
” “This is a function to see if
the food to be searched for is in the
try:
count = fridge[wanted_food]
except KeyError:
count = 0
return count
except KeyError:
count $=0$
return count
The docstring is referenced through a name that is part of the function, almost as though the function were a dictionary. This name is doc and it’s found by following the function name with a period and the name _ doc..

## 统计代写|python代考|Putting Your Program into Its Own File

Python 具有使您能够将代码段收集到更方便的分组中的功能，这些分组可以在您需要时调用。

## 统计代写|python代考|Grouping Code under a Name

>>>冰箱=\left{\right.$‘苹果’$: 10$, ‘橙子’$: 3$, ‘牛奶’$\left.1 k^{\prime}\right}=\left{\right.$‘苹果’$: 10$, ‘橙子’$: 3$, ‘牛奶’$\left.1 k^{\prime}\right}
>>Wanted_food = ‘苹果’
>>in_fridge(l)
10
>>Wanted_food = ‘橘子’
>>>in_fridge()
3
>>>Wanted_food = ‘牛奶’
>>in_fridge(1)
2

## 统计代写|python代考|Describing a Function in the Function

def in_fridge (\rangle :
*”这是一个查看冰箱是否有食物的函数。

try:
count =冰箱[wanted_food]
def in_fridge ():
” “这是一个查看

try中的函数：
count =冰箱[wanted_food]

count = 0

count=0
return count

## 有限元方法代写

tatistics-lab作为专业的留学生服务机构，多年来已为美国、英国、加拿大、澳洲等留学热门地的学生提供专业的学术服务，包括但不限于Essay代写，Assignment代写，Dissertation代写，Report代写，小组作业代写，Proposal代写，Paper代写，Presentation代写，计算机作业代写，论文修改和润色，网课代做，exam代考等等。写作范围涵盖高中，本科，研究生等海外留学全阶段，辐射金融，经济学，会计学，审计学，管理学等全球99%专业科目。写作团队既有专业英语母语作者，也有海外名校硕博留学生，每位写作老师都拥有过硬的语言能力，专业的学科背景和学术写作经验。我们承诺100%原创，100%专业，100%准时，100%满意。

## MATLAB代写

MATLAB 是一种用于技术计算的高性能语言。它将计算、可视化和编程集成在一个易于使用的环境中，其中问题和解决方案以熟悉的数学符号表示。典型用途包括：数学和计算算法开发建模、仿真和原型制作数据分析、探索和可视化科学和工程图形应用程序开发，包括图形用户界面构建MATLAB 是一个交互式系统，其基本数据元素是一个不需要维度的数组。这使您可以解决许多技术计算问题，尤其是那些具有矩阵和向量公式的问题，而只需用 C 或 Fortran 等标量非交互式语言编写程序所需的时间的一小部分。MATLAB 名称代表矩阵实验室。MATLAB 最初的编写目的是提供对由 LINPACK 和 EISPACK 项目开发的矩阵软件的轻松访问，这两个项目共同代表了矩阵计算软件的最新技术。MATLAB 经过多年的发展，得到了许多用户的投入。在大学环境中，它是数学、工程和科学入门和高级课程的标准教学工具。在工业领域，MATLAB 是高效研究、开发和分析的首选工具。MATLAB 具有一系列称为工具箱的特定于应用程序的解决方案。对于大多数 MATLAB 用户来说非常重要，工具箱允许您学习应用专业技术。工具箱是 MATLAB 函数（M 文件）的综合集合，可扩展 MATLAB 环境以解决特定类别的问题。可用工具箱的领域包括信号处理、控制系统、神经网络、模糊逻辑、小波、仿真等。


text:
# KUKA XYZ-ABC format¶

KUKA robots use the so called XYZ-ABC format. $$XYZ$$ is the position in millimeters. $$ABC$$ are angles in degrees, with $$A$$ rotating around $$z$$ axis, $$B$$ rotating around $$y$$ axis and $$C$$ rotating around $$x$$ axis. The rotation convention is $$z$$-$$y'$$-$$x''$$ (i.e. $$x$$-$$y$$-$$z$$) and computed by $$r_z(A) r_y(B) r_x(C)$$.

## Conversion from KUKA-ABC to quaternion¶

The conversion from the $$ABC$$ angles in degrees to a quaternion $$q=(\begin{array}{cccc}x & y & z & w\end{array})^T$$ can be done by first converting all angles to radians

$\begin{split}A_r = A \frac{\pi}{180} \text{,} \\ B_r = B \frac{\pi}{180} \text{,} \\ C_r = C \frac{\pi}{180} \text{,} \\\end{split}$

and then calculating the quaternion with

$\begin{split}x = \cos{(A_r/2)}\cos{(B_r/2)}\sin{(C_r/2)} - \sin{(A_r/2)}\sin{(B_r/2)}\cos{(C_r/2)} \text{,} \\ y = \cos{(A_r/2)}\sin{(B_r/2)}\cos{(C_r/2)} + \sin{(A_r/2)}\cos{(B_r/2)}\sin{(C_r/2)} \text{,} \\ z = \sin{(A_r/2)}\cos{(B_r/2)}\cos{(C_r/2)} - \cos{(A_r/2)}\sin{(B_r/2)}\sin{(C_r/2)} \text{,} \\ w = \cos{(A_r/2)}\cos{(B_r/2)}\cos{(C_r/2)} + \sin{(A_r/2)}\sin{(B_r/2)}\sin{(C_r/2)} \text{.}\end{split}$

## Conversion from quaternion to KUKA-ABC¶

The conversion from a quaternion $$q=(\begin{array}{cccc}x & y & z & w\end{array})^T$$ with $$||q||=1$$ to the $$ABC$$ angles in degrees can be done as follows.

$\begin{split}A &= \text{atan}_2{(2(wz + xy), 1 - 2(y^2 + z^2))} \frac{180}{\pi} \\ B &= \text{asin}{(2(wy - zx))} \frac{180}{\pi} \\ C &= \text{atan}_2{(2(wx + yz), 1 - 2(x^2 + y^2))} \frac{180}{\pi}\end{split}$


text:
## Overview

Being an Intune administrator means that in addition to managing and deploying endpoints, you are also somewhat responsible for ensuring that they continue to comply to the security standards set forth by your company.

Likewise, you may have heard a lot about utilizing Microsoft Defender for Endpoint to construct logic apps and do threat-hunting queries, and you may want to give those a shot as well. Excellent! Starting off with some field notes, I’ve included a few use cases that you should also try or implement to gain a better grasp of your devices and their security posture.

## The Need

Proactively detecting and eliminating advanced threats via threat hunting is becoming increasingly important for many organizations and is actually a time consuming task. However, you may set up rules that automatically adjust to your security policies in accordance with the most recent threat information.

There are many ways to achieve this automation, like:

1. Automating SIEM/EDR/ATP queries
2. Use runbooks for automation of incidents
3. Use Logic apps
4. Automate queries & reports using Power Automate & PowerApps
5. Create dashboards using Power BI

Now, let’s get into some threat-hunting ideas to look for and build some simple must have queries.

## Devices Not Onboarded to MDE

It is quite common in any environment to have endpoints that have not been successfully onoarded to defender for endpoint. Such devices are shown as “can be onoarded” in recommendations. Logging into your Defender admin portal and verifying the list on daily basis can be a daunting task. However you can easily automate this by scheduling a report of such devices using Power Automate or Logic Apps.

I am using Power Automate for this and the configuration is as below:

1. Sign in to Power Automate.
2. Select My flows > New flow > Scheduled cloud flow.
1. In the fields next to Starting, specify the date and time when your flow should start.
2. In the fields next to Repeat every, specify the flow’s recurrence.
3. Select Create.
4. Select Recurrence > Show advanced options and configure the schedule.
1. Choose Microsoft Defender Advance Hunting for the new step and type your query:
1. Create a CSV to export all the results from the query.
1. Schedule the report.

## Local Admin Report

This is one of the most common requirements and you can easily use KQL query in the Advanced Hunting to create & schedule a report for machines having users added as local admin to them.

DeviceLogonEvents
| where Timestamp >= ago(7d)
| where IsLocalAdmin == true

| summarize count() by DeviceName, AccountName,LogonType
| sort by AccountName

## Hunting For Legacy Authentication

Basic authentication has been depreciated so it’s time to hunt down the applications and clients with Basic Authentication and switch to newer authentication methods.

SigninLogs
| where ClientAppUsed !in ("Mobile Apps and Desktop clients", "Browser")
| where isnotempty(ClientAppUsed)
| evaluate pivot(ClientAppUsed, count(), UserPrincipalName)

You can easily automate a daily report using it in Power Automate.

If you are using Microsoft Defender for Endpoint for your Android Enterprise and iOS devices then there are certain configurations required in defender portal to avoid unnecessary alerts on end-users devices.

## Whitelist Your Trusted Root Certificate

If you are deploying trusted root certificates on your enterprise devices then you might receive alerts in defender portal for “Suspicious certificates installed on one endpoint”. Since these devices are corporate owned devices and have your root certificate installed then you can classify these alerts as false positive i.e. detected and identified as malicious even though the entity isn’t actually a threat.

Only apps/programs signed with the exact signed certificate uploaded as indicator are affected. Do not expect to upload a root certificate and all sub certificates will be handled the same.

The full chain of trust for the certificate must be valid and either be trusted through a root certificate in the Microsoft Trusted Root Program or the root certificate must be present in the Trusted Root Certification Authorities store.

To do so, the steps are as below:

1. Select Settings > Endpoints > Indicators (under Rules) in the navigation pane.
2. Select Add indicator.
1. Specify the following details:
• Indicator – Specify the entity details and define the expiration of the indicator.
• Action – Specify the action to be taken and provide a description.
• Scope – Define the scope of the machine group.
1. Review the details in the Summary tab, then click Save.

## Supress iOS/Android Upgrade Notifications

If you have configured software update deferral policies for your iOS & Android Enterprise devices then you might observe that the end users are ntofied to update iOS update notifications in Defender for Endpoint app. And this causes confusion and a bad user experience.

To avoid these notifications on end user’s devices, you simply need to create an exception for iOS Upgrade in Defender portal. The process is pretty simple- select the security recommendation for iOS update and then select Exception options and fill out the form.

These are merely a few extremely simple instances, and the list is by no means complete. You can engage in a wide variety of approaches and methods when hunting. As you begin to evaluate your environment and choose the types of approaches and data you can use, your hunting maturity will increase.


text:
MathSciNet bibliographic data MR2496050 14J29 (14J10 14J17 57R17) Park, Heesang; Park, Jongil; Shin, Dongsoo A simply connected surface of general type with \$p\sb g=0\$$p\sb g=0$ and \$K\sp 2=4\$$K\sp 2=4$. Geom. Topol. 13 (2009), no. 3, 1483–1494. Article

For users without a MathSciNet license , Relay Station allows linking from MR numbers in online mathematical literature directly to electronic journals and original articles. Subscribers receive the added value of full MathSciNet reviews.


text:
# Bibliography tools that are compatible with biblatex and biber

I’m currently in the process of reconsidering how I do bibliography management. It seems to be most sensible to use biblatex with biber. I’d like to know what tools are available on which I can build a solution that works for me. I’m interested in everything from full-blown bibliography management suites to pretty-printers for .bib files; both as traditional programs and online services.

Tools in question should fulfill the following criteria:

• Unicode support.
• Support for the additional entry types and fields that biblatex supports.
• Support for biber’s improved cross-referencing.
-
If I am right then `bibtool` also supports biblatex data bases –  Herbert Jul 24 '11 at 10:36
You can use Emacs for biblatex and biber. –  N.N. Feb 15 '13 at 15:23
Is `Mendeley` (desktop) not compatible ? –  nutty about natty Apr 1 '13 at 19:43

I am most familiar with JabRef. It has Unicode support and a `biblatex` mode. You can also customize JabRef to have any entry type and field you can think of. There is no built-in cross-referencing support in JabRef, but you can set up the corresponding fields yourself.

The newest version of Citavi (3.1) has `biblatex` support as well, as the announcement (at least in German) states. This might not be complete, since it is the first version with `biblatex` support. Citavi has a built-in cross-referencing functionality, but the workflow with LaTeX is not intuitive, as Citavi does not store the data in .bib format.

JabRef works on all platforms (with Java), Citavi is Windows only. Development for a Mac version have stopped in November 2011 (Link).

-
+1 for JabRef :-) –  Tobi Jul 24 '11 at 14:32
By the way, JabRef has BibLaTeX mode (Options -- Preferences -- Advanced -- BibLaTeX mode). –  Anton Tarasenko Sep 2 '11 at 17:32
@Anton, you are right. I edited my answer. –  domwass Sep 4 '11 at 15:22
@Matthias, JabRef‘s biblatex mode changes the available entry types (collection, e.g.) and fields (it adds fields to the optional tab and has a second optional tab with more fields). –  domwass Nov 30 '11 at 13:12
It has to be said though that a lot of time after this answer was posted the JabRef biblatex mode is still not complete. Most importantly, the indication whether an entry is complete still doesn't work properly when only year or date are present but not both. –  Christian Aug 20 '12 at 22:41

For the Mac there is BibDesk, which is a full-featured reference management system that integrates nicely with the Mac OS, and with Mac editors. It allows you to:

• manage references, including documents attached to the references
• create custom bib fields (including those used by `biblatex`)
• search the database and create smart groups of references based on search criteria
• import references from major online sources as well as copied text
• export references and bibliographies in a variety of formats
• autocompletion of `\cite` references in text editors; currently TeXShop is the only program to use this
• System Services for inserting references in other text editors
• support for any text encoding implemented by Apple (e.g., UTF-8, Latin-1, Mac Roman)

In the BibDesk wiki (BibDesk Tips and Tricks) there is some information on customizing BibDesk for `biblatex`, including a link to a TypeInfo file that can be used to create all of the `biblatex` fields automatically. Download the file from here: TypeInfo for BibLaTeX, quit BibDesk, and save the file as `~/Library/Application Support/BibDesk/TypeInfo.plist`, where `~` denotes your home folder. In 10.7 and later, you may need to make this folder visible in Finder.

BibDesk has full support for BibTeX crossrefs (searching, editing, display), but does not support any biber or biblatex additions in this regard. BibTeX macros are likewise fully supported.

-

I use `Zotero` + `Biblatex` + `Biber` backend + `TexStudio` as workflow for automation of bibliography citations. You may want to have a look at my answer here, you can give it a try and let me know if that works fine with you.

-


text:
# 9.3: Rearrangement of Carbocations

Often, dehydrohalogenation or dehydration reactions result in the formation of several products. For example, while we may be able to justify the formation of the first product in the following reaction, can we draw arrows to produce the other two? Well, this would involve $$σ_{C-C}$$ bond cleavage, or rearrangement of the carbon skeleton.

Rearrangements occur when the formation of a carbocation results in a reorganization of the $$σ$$-framework to generate a more stable carbocation. This occurs when $$σ$$-donation goes “too far” and the $$σ$$ bond is actually broken.

Let’s take a look at the rearrangement step via a Newman projection. A $$σ_{C-C}$$ bond is overlapping with the atomic p orbital. This weakens the $$σ_{C-C}$$ bond so much that it actually breaks and moves over (1,2-methyl shift) to generate a new carbocation, which can then proceed to undergo other things (substitution or elimination reactions).

Normally, rearrangements occur because these shifts (1,2-methyl, 1,2-hydride, 1,2-alkyl, etc..) result in a more stable carbocation.

There are some special cases of rearrangements that we must be aware of:

Improper orbital alignment - $$σ_{C-H}$$ and $$σ_{C-C}$$ bonds that aren’t aligned properly with an atomic p orbital will not migrate, even if a more stable carbocation would result.

Ring expansions - $$σ_{C-C}$$ bonds can migrate to form larger, more stable rings that relieves ring strain. This is known as a Wagner-Meerwein shift.

Ring contraction - $$σ_{C-C}$$ bonds can migrate to form smaller rings. The best example of this is the pinacol rearrangement. The driving force for this reaction is the formation of a C=O bond (the carbocation resulting from the rearrangement is resonance-stabilized).

9.3: Rearrangement of Carbocations is shared under a CC BY-NC-SA 4.0 license and was authored, remixed, and/or curated by LibreTexts.


text:
# Tag Info

What you are referring to is the same weakness in regard to malleability that is also applicable to (non-hashed schoolbook) RSA. In Elgamal an attacker can (in practice) not decrypt the transferred and encrypted message, but he can modify (factor) it and is able to determine the effect of his modification. Let $y$ be the original encrypted message of the ...


text:
# Can $\sum_{i=0}^n (k^i)/i!$ be simplified?

Can this expression be simplified?

$\sum_{i=0}^n (k^i)/i!$

EDIT: This expression I have got as the number of possible ways to select n objects or less from k different infinite objects (you can select as many as you can from any type)...

I believe it must be equal to the number of possible ways to select n objects from k+1 different infinite objects, where the extra +1 is a dummy object, selecting one of this type means letting an empty space in the final selection (i.e. selecting n-1 not n)...

so this must be equal to:

$(k+1)^n/n!$

Why that is not right??

-
Note that 1 plus this expression would be a truncation of the power series for exp(k). Perhaps you meant to start the summation at i=0? In any case this is a polynomial in k. There are more efficient ways to evaluate it than term-by-term, e.g. Horner's method. Is that the kind of "simplification" you have in mind? –  hardmath Nov 30 '10 at 12:05
That truncation of the exponential function can be expressed as an incomplete gamma, but my opinion is that's the simplest you can get for that sum, computationally speaking. –  Guess who it is. Nov 30 '10 at 12:06
Speaking of which... –  Guess who it is. Nov 30 '10 at 12:08
Not so relevant, but for $k=n$ this expression is asymptotically $e^n / 2$ as $n \to \infty$ (by the central limit theorem). –  Shai Covo Nov 30 '10 at 12:32
Are you sure $k^i/i!$ is the right expression? Maybe you want $\binom{k+i-1}{i-1}$? –  Yuval Filmus Nov 30 '10 at 17:38

Your reasoning is incorrect. $\frac{k^i}{i!}$ is not even an integer in general, so it can't count what you're claiming it counts. While $k^i$ is the number of ways to choose $i$ objects from $k$ types of objects in order, you can't just divide by $i!$ to get rid of the ordering because some of the orderings are the same when you rearrange them.

For example, if $k = 2, i = 3$, then the possible ways to choose $3$ objects from $2$ types of objects in order are $AAA, AAB, ABA, ABB, BAA, BAB, BBA, BBB$, and the possible ways to choose $3$ objects from $2$ types are $AAA, AAB, ABB, BBB$, which is $4$ and not $\frac{2^3}{3!} = \frac{4}{3}$. When you are dividing by $3!$ you are pretending that the different orderings group evenly into groups of $6$ but, as you can see, they don't.

The actual number you want, for fixed $i$, is the number of multisets of $i$ objects on a $k$-element set, which is actually

$${k+i-1 \choose i}.$$

This can be proven using what's called the "stars and bars" argument, as well as Burnside's lemma. Note that if $i$ is fixed and $k$ tends to infinity this is asymptotically, but not exactly, $\frac{k^i}{i!}$.

As you say, if you want the number of multisets of $n$ or less objects, then you just add in a dummy element of the set, so the final answer is

$$\sum_{i=0}^n {k+i-1 \choose i} = {k+n \choose n}.$$

This identity is sometimes known as the hockey-stick identity because it has an interpretation in terms of summing along a hockey-stick-like shape on Pascal's triangle.

-
Unless I've remembered combinatorials wrongly you're saying f(1,n)=(1+n n+1)=1, but I believe it should be n (or n+1, to include none). –  Mark Hurd Feb 17 '11 at 7:29
Yes, you're right, I messed up the indexing slightly. Thanks. –  Qiaochu Yuan Feb 17 '11 at 9:03
Here's an aside question: I've seen $\left(\!\!\binom{n}{k}\!\!\right)$ used for the multiset coefficients in a couple places. Is this standard notation? –  user4689 Feb 17 '11 at 12:50
@Graham: more or less. It is used, for example, in Stanley's book. –  Qiaochu Yuan Feb 17 '11 at 13:28

In response to the edited question, it is not right. If we just let n=2, $1+k+\frac{k^2}{2}\neq \frac{(k+1)^2}{2}$. The difference is $\frac{1}{2}$

-
But what is wrong with the assumption then? –  Betamoo Nov 30 '10 at 16:29

Your existing formula does not produce integers all the time:

Consider number of types, k=1

I believe that means f(k,n)=n

Your f(1,n)= $\sum_{i=0}^n 1/i!$ which is definitely not generally an integer.

What you want is

$\sum_{i=0}^n g(k,i)$

where g(k,i) is the number of ways you can select exactly i objects from upto k types.

Which can be similarly expanded to

$\sum_{i=0}^n \sum_{j=0}^k h(j,i)$

where h(j,i) is the number of ways you can select exactly i objects from exactly j types.

Note, because h(j,i)=0,i<j, we can swap the summations:

$\sum_{j=0}^k \sum_{i=j}^n h(j,i)$

[ and l(j,n)=$\sum_{i=j}^n h(j,i)$ is the number of ways you can select between j and n objects from exactly j types which is the same as selecting between 0 and n-j objects from up to j types thus l(j,n)=$\sum_{i=0}^{n-j} g(j,i)$ so f(k,n)=$\sum_{i=0}^n g(k,i) = \sum_{j=0}^k \sum_{i=0}^{n-j} g(j,i)$ ]

One of g or h (or l) should be definable using combinations as suggested by Yuval Filmus's comment.

-


text:
# General number field sieve is slower then exhaustive search for 'small' numbers?

In an attempt to understand the efficiency of the GNFS, I've been looking at runtimes. The calculations seem to indicate the GNFS runs slower than exhaustive search for smallish n. For example: suppose I want to factor the number 247 (ie 13 * 19).

To do this I can just check all the numbers (exhaustive search) below $$\sqrt{247} \approx 16$$ to see if they divide 247.

The General number field sieve has a runtime of $$\approx \exp \sqrt[3]{\frac{64}{9}} (\ln n)^{1/3} (\ln \ln n)^{2/3},$$

So calculating the GNFS runtime... $$\approx \exp \sqrt[3]{\frac{64}{9}} (\ln 247)^{1/3} (\ln \ln 247)^{2/3},$$ $$\approx \exp \sqrt[3]{\frac{64}{9}} (5.5)^{1/3} (\ln 5.5)^{2/3},$$ $$\approx \exp \sqrt[3]{\frac{64}{9}} (5.5)^{1/3} (1.7)^{2/3},$$ $$\approx \exp (1.9 * 1.8 * 1.4),$$ $$\approx \exp (4.87) \approx 120$$

This is obviously bigger than 16. What am I missing here?

• This is somewhat tangential, but practical implementations generally don't use GNFS until ~ 100 digits, as it is slower than other methods below that point. Full trial division (exhaustive search) typically beats other methods with input under 6 or 7 digits (until 1M or so). Jul 19 '16 at 20:22


text:
1. We don't have a wiki here yet...
2. We don't have a wiki here yet...
3. We don't have a wiki here yet...
4. Born and raised in and around some of the best bands to come out of Reno Nevada, 1618 is a collaboration of people from all different…

5. We don't have a wiki here yet...
6. We don't have a wiki here yet...
7. We don't have a wiki here yet...
8. A L.A.-based production duo consisting of AARONMAXWELL & james matthew. The two are behind the cassette label El Sereno Records .

9. We don't have a wiki here yet...
10. 1. A rock band that goes by the name Languid
2. A producer that goes by the name Languid (https://soundcloud.com/languid)


text:
# For which values of $\alpha, \beta$, $\int_0^1 \frac{\ln^\alpha(1+x)}{x^\beta(1-x)^\alpha}\mathrm dx$ exists?

There are 2 improper points: $0, 1$.

I found that $\displaystyle \int_{\frac{1}{2}}^{1}\frac{\ln^\alpha(1+x)}{x^\beta(1-x)^\alpha}\mathrm dx$ exists for $\alpha < 1$ (by using the limit comparison test, with $g(x)=\frac{1}{(1-x)^\alpha}$).

But I'm having trouble picking $g(x)$ for the other interval. If $\alpha \lt 0$ then $\ln^\alpha(1+x) \underset{x\to 0}{\to} \infty$, and everything I try gives me $\frac{f(x)}{g(x)}\to 0$ or $\frac{f(x)}{g(x)}\to \infty$ which doesn't give me all possible solutions.

-
For the behavior near 0 you can ignore the 1/(1 - x)^a term. Then the problem is to compare the logarithm in the numerator with the power function in the denominator. Are you familiar with the first few terms in the Taylor expansion of ln(1 + x)? – Qiaochu Yuan Dec 3 '10 at 17:01
I made that observation regarding 1/(1 - x)^a aswell. We just started learning about Taylor expansions but I think we're expected to solve this without that material. – daniel.jackson Dec 3 '10 at 17:22
If I am not mistaken, for $0<\beta <1$, since $\displaystyle\int_{0}^{1/2}\dfrac{1}{x^\beta}dx$ converges, $\dfrac{\ln ^{\alpha }(1+x)}{x^{\beta }(1-x)^{\alpha }}/(1/x^{\beta })$ tends to $0$ with $x$ and your integral converges. – Américo Tavares Dec 3 '10 at 17:55
Why? If $\alpha \lt 0, \ln^\alpha(1+x) \underset{x\to 0}{\to} \infty$. And still if $0 \leq \alpha \lt 1$, what about $\beta \geq 1$? The LCT gives no conclusion when $g(x)$ doesn't converge and $\frac{f(x)}{g(x)}\to 0$ – daniel.jackson Dec 3 '10 at 18:07
The condition is only $\beta<1$ – Américo Tavares Dec 3 '10 at 18:13
show 6 more comments

We can pick $g(x)=\frac{1}{x^(\beta-\alpha)}$ and then $\frac{f(x)}{g(x)}\to 1$ as $x\to 0$. By the LCT we get $\int_{0}^{\frac{1}{2}}\frac{\ln^\alpha(1+x)}{x^\beta(1-x)^\alpha}$ exists iif $\beta-\alpha \lt 1$.
So overall $\int_{0}^{1}\frac{\ln^\alpha(1+x)}{x^\beta(1-x)^\alpha}$ exists iif $\beta-1 \lt \alpha \lt 1$.


text:
Browse Questions

# An eco system must have a continuous external source of

$\begin{array}{1 1}(a)\;\text{Minerals}\\(b)\;\text{Energy}\\(c)\;\text{Food}\\(d)\;\text{All of these}\end{array}$

An eco system must have a continuous external source of energy.
Hence (b) is the correct option.


text:
In general, this is not well-defined (you could look at the completion of the category by homotopy colimits, I guess, but for some reason I feel like this isn't very useful). A sheaf on the geometric realization is equivalent to a covering space. The geometric realization throws out too much data for this sort of thing to be very useful. You should really read HTT by Lurie, because this is what the book is about ([generalizations of] sheaf toposes on infinty-categories (which are special simplicial sets). You usually want to look at sheaves of Kan complexes, which are a higher-categorical equivalnt of categories fibered in groupoids.

Technically you can view any simplicial set as the $\omega$-nerve of a strict $\omega$-category, so in that sense, you could look at strict $\omega$-functors, but these are of very little interest in general.

I answered a similar question to this a while back.

Specifically the question was asking about the result that the category covering spaces on BC:=|N(C)| is canonically isomorphic to presheaves on C.

3 added 147 characters in body

In general, this is not well-defined (you could look at the completion of the category by homotopy colimits, I guess, but for some reason I feel like this isn't very useful). A sheaf on the geometric realization is equivalent to a covering space. The geometric realization throws out too much data for this sort of thing to be very useful. You should really read HTT by Lurie, because this is what the book is about ([generalizations of] sheaf toposes on infinty-categories (which are special simplicial sets). You usually want to look at sheaves of Kan complexes, which are a higher-categorical equivalnt of categories fibered in groupoids.

Technically you can view any simplicial set as the $\omega$-nerve of a strict $\omega$-category, so in that sense, you could look at strict $\omega$-functors, but these are of very little interest in general.

I answered a similar question to this a while back.

2 added 212 characters in body

In general, this is not well-defined (you could look at the completion of the category by homotopy colimits, I guess, but for some reason I feel like this isn't very useful). A sheaf on the geometric realization is equivalent to a covering space. The geometric realization throws out too much data for this sort of thing to be very useful. You should really read HTT by Lurie, because this is what the book is about ([generalizations of] sheaf toposes on infinty-categories (which are special simplicial sets). You usually want to look at sheaves of Kan complexes, which are a higher-categorical equivalnt of categories fibered in groupoids.

Technically you can view any simplicial set as the $\omega$-nerve of a strict $\omega$-category, so in that sense, you could look at strict $\omega$-functors, but these are of very little interest in general.

1


text:
Main

# Decision Trees

The goal of this part is to write a script to compute the decision tree for an input dataset. You can assume that all attributes are numeric, except for the last attribute which is the class.

You should use the Information Gain based on Entropy for computing the best split value for each attribute. For the stopping criteria at a node, stop if the purity is at least 95% or stop if the node size is five or lower.

Note that the best way to implement the splits for numeric attributes is to sort the values of that attribute from smallest to largest. Then you can use the mid-point between two distinct (consecutive) values as the split test of the form $$A \le v$$. You can then update the class frequencies on both sides of the split and compute the split entropy for each decision. After comparing with the entropy for the node, you can find the best split for the current attribute. Now repeat the whole process for each numeric attribute at that node, and choose the best split over all attributes. Finally, split the data according to the best split, and repeat the whole method recursively, until the stopping conditions are met.

Your script should output the final decision tree using the format described below. For example, for toy data below:

AgeCarTypeRisk
251L
203H
251L
452H
201H
252H

The decision tree should be printed in the following format:

Decision: Car <= 1.5 , Gain= 0.4591479
Decision: Age <= 22.5 , Gain= 0.9182958
Leaf: label= H purity= 1 size= 1
Leaf: label= L purity= 1 size= 2
Leaf: label= H purity= 1 size= 3

Note that each internal node, print the decision followed by the Information Gain, and for each leaf, print the majority label, purity of the leaf, and the size. The indentation indicates the tree level. All nodes at the same level of indentation (tabs) are at the same level in the tree. For the tree above, $$Car <= 1.5$$ is the root decision. Its left child is $$Age <= 22.5$$, and its right child is a leaf. Also, for $$Age \le 22.5$$ its left and right children appear immediately below it.

You may test your program on the iris.txt dataset.


text:
# Forget Hooke's law. Why does a spring exert a force?

Forgetting Hooke's law for a minute why, from a microscopic perspective (preferably quantum) on up to a macroscopic one, does a spring under tension exert a force?

I was thinking that there might be an analogy between the high and low pressure states of an air wave and the density of the mass distribution of the compressed and stretched states of an iron spring, but I don't know nearly enough about solid state physics to even guess.

-
Because springs represent a macroscopic example of an ubiquitous type of potential - the simple harmonic oscillator. –  crasic Jun 6 '11 at 8:40

You could make an analogy between the pressure distribution of a sound wave and the mass density distribution of a realistic spring undergoing vibrations, but it wouldn't give you the explanation you're looking for. As a matter of fact, that would be more like explaining a sound wave in terms of springs, rather than what you're trying to do, i.e. explaining a spring in terms of waves.

Although I'm not intimately familiar with the details, basically what goes on at the microscopic level of a spring is that, when the spring is at equilibrium, the atoms are set in some sort of rigid structure. Any given pair of atoms has a potential energy which is a function of the distance between those two atoms, so the entire spring has a potential energy determined by all the distances between every possible pair of atoms:

$$U = \sum_{i,j} U_{ij}(r_{ij})$$

In equilibrium, the spring will take a shape which minimizes this total potential energy.

If you think about it, a metal spring might typically be formed by heating some metal to make it malleable (or even melting it), and then forming it into the desired shape before it cools. The heat allows the atoms to move around relatively freely so that they can reach the equilibrium configuration that minimizes their potential energy, then once the spring cools, they are frozen in place.

Of course, the atoms are not completely frozen in place. As I see that Georg has already written in his answer, the potential energy between two atoms ($U_{ij}(r_{ij})$) has a minimum at their equilibrium distance and goes up on either side. If you add some energy into the system, say by exerting a force on it, you can get the atoms to move closer together or further apart. When you stretch or compress a string, you are really just doing this to all the (pairs of) atoms in the spring simultaneously. The atoms will, of course, "try" to return to their equilibrium position, i.e. they will "try" to minimize their potential energy, and this is what you feel as the restoring force of a spring under tension.

-

Expanding on my comment.

A spring, or anything that can be modeled by a string is any interaction that can be described by a potential that is proportional to $x^2$ the displacement. Why is this potential important? Qualitatively, it is the solutions to this potential (i.e. the motion of a particle that sits in this potential) are the solutions of a simple harmonic oscillator i.e. Sine Waves.

In a very hand wavy approach to this. You can think that to the lowest order the universe is host to 2 ubiqutious potentials - the $1/x$ potential that is responsible for our inverse square laws and the $x^2$ potential responsible for oscillations and harmonic motions. A constant potential will exert no force and an $x^1$ potential will exert a force on an object that is constant at all distances - clearly unphysical.

More specifically, a simple equation to model the potential "felt" by two neutral atoms clsoe to each other is given in the Lennard-Jones potential A graph of which is shown below. This type of potential is somewhat ubiquitous (in one form or another) when taking about intermolecular interactions. There are refinements, expansions, better models, etc. But they all have one thing in common a "minimum" or a "cup" in the potential which represents the stable configuration. A particle/atom/crystal/etc. that exists in that region of the potential is "stable". Nudge it in one direction and it will naturally "fall" towards the low point of the potential.

Why is this important? Well, to first approximation the region near the low point of the potential is effectively a $x^2$ potential - a simple harmonic oscillator. Thus any system that is modeled by this potential will respond like a harmonic oscillator in the limit of a really small nudge. I.e. it behaves like a spring. Due to the magic of ignoring all mathematical rigor, effectively any potential that vaguely looks like the L-J potential, in fact any potential that has a local minimum like such, will to first order look like a $x^2$ potential in the small region around the minimum.

-
I would appreciate an explanation for the downvote –  crasic Jun 6 '11 at 11:14
This is 1st for rechurning, second for nonsense of harmonic oscillator. For elastic behaviour the exact form of the potential is irrelevant. ""like a harmonic oscillator in the limit of a really small nudge. I.e. it behaves like a spring."" Not all elastic materials follow Hookes law. (Which should be forgotten here, remember? –  Georg Jun 6 '11 at 11:40
@Georg Provided that the above graph is of the potential between two particles and that it has a continuous 2nd derivative at the minimum, which is the rest point, it follows Hookes law. Now, I don't personally understand the harmonic oscillator part and find the $x^2$ to obviously contradict the graph, but that's not my area. –  Alan Rominger Jun 7 '11 at 14:13


text:
# naginterfaces.library.lapackeig.dgelsd¶

naginterfaces.library.lapackeig.dgelsd(a, b, rcond)[source]

dgelsd computes the minimum norm solution to a real linear least squares problem

For full information please refer to the NAG Library document for f08kc

https://www.nag.com/numeric/nl/nagdoc_28.5/flhtml/f08/f08kcf.html

Parameters
afloat, array-like, shape

The coefficient matrix .

bfloat, array-like, shape

The right-hand side matrix .

rcondfloat

Used to determine the effective rank of . Singular values are treated as zero. If , machine precision is used instead.

Returns
afloat, ndarray, shape

The contents of are destroyed.

bfloat, ndarray, shape

is overwritten by the solution matrix . If and , the residual sum of squares for the solution in the th column is given by the sum of squares of elements in that column.

sfloat, ndarray, shape

The singular values of in decreasing order.

rankint

The effective rank of , i.e., the number of singular values which are greater than .

Raises
NagValueError
(errno )

On entry, error in parameter .

Constraint: .

(errno )

On entry, error in parameter .

Constraint: .

(errno )

On entry, error in parameter .

Constraint: .

(errno )

The algorithm for computing the SVD failed to converge; off-diagonal elements of an intermediate bidiagonal form did not converge to zero.

Notes

dgelsd uses the singular value decomposition (SVD) of , where is a real matrix which may be rank-deficient.

Several right-hand side vectors and solution vectors can be handled in a single call; they are stored as the columns of the right-hand side matrix and the solution matrix .

The problem is solved in three steps:

1. reduce the coefficient matrix to bidiagonal form with Householder transformations, reducing the original problem into a ‘bidiagonal least squares problem’ (BLS);

2. solve the BLS using a divide-and-conquer approach;

3. apply back all the Householder transformations to solve the original least squares problem.

The effective rank of is determined by treating as zero those singular values which are less than times the largest singular value.

References

Anderson, E, Bai, Z, Bischof, C, Blackford, S, Demmel, J, Dongarra, J J, Du Croz, J J, Greenbaum, A, Hammarling, S, McKenney, A and Sorensen, D, 1999, LAPACK Users’ Guide, (3rd Edition), SIAM, Philadelphia, https://www.netlib.org/lapack/lug

Golub, G H and Van Loan, C F, 1996, Matrix Computations, (3rd Edition), Johns Hopkins University Press, Baltimore


text:
# Toptable error, wont recognize condition

I am getting a rather strange error from topTable. When I run my code I get Error in fit$coefficients[, coef] : subscript out of bounds from topTable as if it is not recognizing the condition I am asking it to return the top ten DEGs of. I have provided a bit more context and some descriptions of my variables below. Let me know if you need any more information or if anything is unclear. Variables: dge is a DGEList object of RNA seq data. dge$counts is the raw counts.

dge$samples$dge_meta is the metadata and log2 transformed counts.

> colnames(dge$$samples$$dge_meta)
[1] "Lab.sample.ID"
[2] "Accession.Number"
[3] "Alias.used.in.some.figures"
[4] "Developmental.stage"
[5] "Infected"
[6] "Batch"
[7] "Trimmed"
[8] "Number.of.reads.that.pass.Illumina.filter"
[9] "Total.number.of.reads.mapped"
[10] "%.of.total.reads.mapped"
[11] "Reads.mapped.to.T..cruzi.Esmeraldo.haplotype"
[12] "Reads.mapped.to.hg19"
[13] "%.of.mapped.reads.belonging.to.T..cruzi.Esmeraldo.haplotype"
[14] "%.of.mapped.reads.belonging.to.hg19"
[15] "sample"
[16] "hpi"

Lastly keep_it is a binary vector used to filter our zero count genes.

Code:

mm <- model.matrix(~~hpi*Infected, data = dge$$samples$$dge_meta) #making our design matrix

more_than_1cpm_model <- voom(dge$counts[keep_it,], mm, plot = TRUE) #this one is filtered by the 25% greater than 1 cpm cutoff <- 1e-05 empBayesfit <- eBayes(fit_gt1cpm) topTable(empBayesfit, coef = c("Infected"), p.value = cutoff, number = 10)  Error message: Error in fit$coefficients[, coef] : subscript out of bounds

To understand the context better I ran rlang::last_error and rlang::last_trace as well.

> rlang::last_error()
<error/dplyr_error>
arrange() failed at implicit mutate() step.
* Problem with mutate() input ..1.
x Input ..1 must be a vector, not a standardGeneric object.
i Input ..1 is samples.
Backtrace:
Run rlang::last_trace() to see the full context.
> rlang::last_trace()
<error/dplyr_error>
arrange() failed at implicit mutate() step.
* Problem with mutate() input ..1.
x Input ..1 must be a vector, not a standardGeneric object.
i Input ..1 is samples.
Backtrace:
x
1. +-dplyr::arrange(x, samples)
2. +-dplyr:::arrange.data.frame(x, samples)
3. | \-dplyr:::arrange_rows(.data, dots)
4. |   +-base::withCallingHandlers(...)
5. |   +-dplyr::transmute(new_data_frame(.data), !!!quosures)
6. |   \-dplyr:::transmute.data.frame(new_data_frame(.data), !!!quosures)
7. |     +-dplyr::mutate(.data, ..., .keep = "none")
8. |     \-dplyr:::mutate.data.frame(.data, ..., .keep = "none")
9. |       \-dplyr:::mutate_cols(.data, ...)
10. |         +-base::withCallingHandlers(...)
11. |         \-mask$eval_all_mutate(quo) 12. +-dplyr:::abort_glue(...) 13. | +-rlang::exec(abort, class = class, !!!data) 14. | \-(function (message = NULL, class = NULL, ..., trace = NULL, parent = NULL, ... 15. | \-rlang:::signal_abort(cnd) 16. | \-base::signalCondition(cnd) 17. +-(function (e) ... 18. | \-rlang::abort(...) 19. | \-rlang:::signal_abort(cnd) 20. | \-base::signalCondition(cnd) 21. \-(function (cnd) ...  • Why does that get downvoted? It contains code and obviously invested effort, being on-topic. At least add a comment what you do not like. This random downvoting thing is so toxic. As for the question, I would run filterByExpr rather than a custom filter, this is probably a bit more reliable. Please show the requested colnames of mm. – ATpoint Mar 29 at 8:55 • @ATpoint Its very annoying as a newcomer to bioinformatics and r and to get that kind of response. I appreciate your comment. I solved the problem on my own, partly it was because of a typo (I had two ~~) but also I had changed something in 'dge$samples\$dge_meta' without realizing it. – Angus Campbell Mar 31 at 2:16
• @ATpoint I downvoted the question and I left an answer (not a comment). Why you question the upvotes too? I don't find the question useful as there are many questions about similar, if not exact, error online. AngusCampbell if you don't want downvotes you can post your questions on support.bioconductor.org were it's not possible to downvote. – llrs Mar 31 at 7:41
• @IIrs If you feel a question is similar to another answer, flag it as such and provide a link to the question you belive provides the answer. Moderators will then close my question or leave it up as other may find it useful. Personally when I search my error with "topTable subscript out of bounds" it is the only question that is returned by that search. This is why I posted the question, nothing came up before when I searched it. ATpoint was not directing criticism at you, the user was commenting on the fact that it seems strange to down vote a question with clear effort invested. – Angus Campbell Mar 31 at 20:28
• @IIrs stack is meant to be a community where we can learn from errors receive feedback. Frankly the way you have answered was sarcastic, I didn't say anything but there are politer ways to respond. Also the voting system is ammonized for a reason to prevent personal confrontations in the comments. So its fine to downvote, and leave a reason for the downvote as its fine for ATpoint to comment on the validity of that downvote but I think by trying to personally go after users you disagree with is not constructive. – Angus Campbell Mar 31 at 20:33

## 1 Answer

The error is telling you that there isn't any Infected column on the model.matrix. Check the column names of mm. Also not sure that having two ~ will work well.

• I did notice the ~~ mistake thanks for pointing it out. – Angus Campbell Mar 31 at 2:16


text:
# How to place boxed text next to an image of the same height?

I'd like to mimic the following style: having an image of an author next to a textbox of the same height.

However, my attempt is humorously unsettling:

It appears that the aspect-ratio of my face has changed, and it is one-line offset from the textbox, dipping down into the abstract line. Here, I'm attempting to scale the image to the height of the textbox, but I'd actually like to scale the textbox to have the height of the image (without changing the aspect ratio):

\noindent\fbox{%
\parbox{\textwidth}{%
\begin{wrapfigure}{r}{0.2\textwidth}
\begin{center}
\includegraphics[width=0.18\textwidth]{boylan.jpg}
\end{center}
\end{wrapfigure}
\textbf{Lyam K. Boylan} is an undergraduate student studying physics and pure mathematics at the
University of Victoria with primary interests in the set theoretic foundations of the universe.
}%
}

With use of valign instruction defined in the adjustbox package, and text and image inserted in tabularx:

\documentclass{article}
\usepackage{tabularx}

\begin{document}
\noindent\begin{tabularx}{\linewidth}{ |X|c @{} }
\cline{1-1}
\textbf{Lyam K. Boylan} is an undergraduate student studying physics and pure mathematics at the \emph{}University of Victoria with primary interests in the set theoretic foundations of the universe.
&   \includegraphics[width=0.2\linewidth,valign=t]{example-image-a}  \\
\cline{1-1}
\end{tabularx}  \\
\begin{tabularx}{\linewidth}{@{} c|X| }
\cline{2-2}
\includegraphics[width=0.2\linewidth,valign=t]{example-image-b}
&   \textbf{Lyam K. Boylan} is an undergraduate student studying physics and pure mathematics at the \emph{}University of Victoria with primary interests in the set theoretic foundations of the universe.\\
\cline{2-2}
\end{tabularx}
\end{document}

• This method ended up working out the best for me. Thank you! – Graviton Mar 29 at 23:12

One posibility: \raisebox

\documentclass{article}
\usepackage{graphicx}
\usepackage{wrapfig}

\begin{document}

\noindent\fbox{%
\parbox{\textwidth}{%
\begin{wrapfigure}[4]{r}{0.3\textwidth}

\raisebox{-11mm}[0pt][0pt]{ \includegraphics[width=0.18\textwidth]{example-image}}

\end{wrapfigure}
\textbf{Lyam K. Boylan} is an undergraduate student studying physics and pure mathematics at the
University of Victoria with primary interests in the set theoretic foundations of the universe.
}%
}

\end{document}


text:
## Geometry: Common Core (15th Edition)

$\frac{176}{55}$ hours distance=rate*time
Subtracting tells us the distance between the two cities. $357-181=176$. We can solve this problem using the formula distance=rate*time. The distance is 176 miles and the rate is 55 mph. Substituting these numbers into the formula gives $176=55t$. Divide both sides by 55 to get the answer in hours, $t=\frac{176}{55}$.