Our next topic is examples of vectors.
[NOISE] Last time, we simply looked at the basics like,
[NOISE], you know, what's a vector?
How do you refer to its entries or its elements?
Um, we looked at the concept of equality, stacking vectors.
Let's see, what else did we talk about?
Um, that is pretty much it, sparse vectors,
unit vectors, ones vectors, special vectors.
Yeah. Um, at- at that point, however,
the- there'd be no reason for you to have any interest whatsoever,
like, who care- what do you do with a ones vector? Like who cares?
Um, right now what we're gonna do is
we're gonna look at some examples and this will hopefully give you
a rough idea of- of the kind- of where you would see and encounter vectors.
Um, hopefully, you'll end up convinced that it's in a whole lot of applications,
uh, that- that vectors come up.
Okay. Um, so let's go to some of the most,
uh, traditional and classical ones, right?
If you take, er, your, you know,
first course and actually sometimes in vector calculus
or if you take a course in physics or mechanics or something like that.
Um, there you encounter a lot of vectors.
Those vectors are usually, uh,
two vectors or three vectors,
meaning that they have dimension two or three.
Uh, I mean, in the real world, it's like three,
at what, er- for us, I mean,
if it's- if it's positions.
And there, uh, what people talk about is, uh,
you can use a vector to- to give a- a location, right?
So for example, here's a vector x,
um, and it's got two entries.
Of course, it's a- it's a two-vector,
so it looks like x_1 and x_2.
And what they represent- what a vector here represents is a position in a plane,
and that's- that's this picture here.
So, uh, you should think of it as- as telling you that,
that dot or the position is there.
So a vector can specify a position,
um, in two dimensions or in three dimensions too.
So, uh, of course,
you have to agree on what the coordinate system is.
[NOISE] You know, and it could be whatever it doesn't matter.
It could be, you know,
the- the traditional one.
Uh, but you have to say what the coordinate system is.
But once you give the coordinate system
a vector- a three-vector will give you a location, okay?
Or a two-vector would give you a location in a plane, that kind of thing.
So that's- that's very common.
And you've seen this, I think these are called,
you know, Cartesian coordinates.
That's- that's what this is.
Okay. Um, now a very- a related concept,
not quite the same, a related one is, um,
you can use a vector to describe displacements, right?
And a displacement does not refer to a position.
What it refers to is a, uh,
actually a- a change in position from one place to another.
So there we- when it's describing a position,
we- we think of it as- we draw it as a dot or an x or something.
Um, a- when we talk about a displacement,
it's usually drawn as an arrow.
Um, and the basic idea is here,
x_1, x_2, as in here, represents a displacement.
And it says that, you know,
from this point to that point, you should move, uh,
to the right by x_1 and you should write above height by x_2,
and that's a displacement.
Um, so that's a- this- this is the kinda thing you would see in your- you know,
in your basic physics class or mechanics or something.
So that's, and this is very
conventional and you probably saw this already in things like that.
Okay. Um, let me mention some others and
I actually frankly find these more interesting. Um, okay.
So first of all, color, uh,
colors that the human eye, uh,
responds to are given by three vectors.
So three numbers; uh, R, G,
and B. Um, and that's the red,
green, and blue intensity level.
And it's very cool.
So you can describe a- a color by giving,
uh, give- uh, by- by giving three numbers.
Uh, for example, uh, the first unit vector E1 means- or it depends how you scale it,
but I'm gonna scale them so that 1 means maximum intensity,
0 means off, okay?
So in that system,
E1, which is the vector 1,
0, 0 is the color pure red, right?
Um, then E3 is pure blue.
Um, the vector like 1, 0,
1 means turn on the red full blast,
turn on the blue, and you're gonna get some very pretty kind of violet or purple color.
That's what it is. But this will give you all sorts of colors, uh,
that's- and they're described by a three-vector.
Um, okay.
Um, another good example is sometimes an n vector is used to give,
uh, like a bill of materials or a list of quantities.
Uh, so for example, um,
you could have 10 raw materials that you
need to dis- to- to build a unit of a product, right?
And then a vector could describe
how many of- how many units of each of
the materials you need to build the product, right?
And so that would be that.
Um, super interesting question there is,
if a vector is sparse,
that means that the list of quantities you're describing,
most things are zero.
Um, so that's an- the exam- that's a good example of a- of a sparse vector.
Um, here's one, a portfolio in finance, right?
So it's very common,
but it's not very common, it's universal.
It is universal in finance.
Uh, when you're describing a portfolio and
a port- portfolio is a collection of assets that you own.
You know, typically stocks,
bonds, options, it doesn't matter whatever they are.
Um, and what a portfolio does is- it's a- uh,
first of all, it's a collection of things that you own.
Um, and there it's represented by a vector.
And the several ways people do this, uh,
it could be that a vector would give you the- uh,
a vector could give you the dollar value of each of the assets.
That's a, that's a common one.
Another one is it could give you the fractions, right?
Um, of your total portfolio,
uh, in- in held in each of these assets, right?
Um, it's also interesting,
we're gonna talk about this later,
maybe not so much right now, um,
that you can actually have negative quantities,
uh, in finance, right?
And what that means is these are called so-called short positions.
And it basically means that you borrowed it from
someone and you're gonna have to pay it back.
So- but we'll talk about that later.
Uh, but it's interesting because it means you can have quantities that are negative,
um, in- in this case, right?
So, um, let's just look at an example.
So here's a portfolio with,
let's say stocks, bonds, and cash.
Just keep it real simple, right?
So here's a portfolio and I'm gonna represent it- I'll represent it in dollar values.
It's 100, 50,
and 20. There you go.
So that portfolio says that you have $100 worth of stocks,
$50 worth of bonds,
and $20 in cash.
That's what it means, okay?
And that- that's a very common way to,
uh, represent a- a- a portfolio.
So that's the idea.
Um, but so that- that's the idea. You for example, we could look at that and we can say,
what's the total, uh,
what is the total value of that portfolio?
And it's the sum of the entries,
and that would be 170.
So if someone says, how much is your portfolio worth?
You'd say, how much is this portfolio worth?
You'd say 100%. Okay. Oh, sorry, $170. Okay.
Um, here's another one.
Uh, a vector can be used to represent a- a cash flow,
um, and that's very interesting,
very, extremely common, right?
So, um, a cash flow could be an- it could be all sorts of- it could be the revenue for,
uh, one of your stores, okay?
And it's the daily amount of cash that came in.
By the way, a bunch of cash is probably also going out,
but that's- you'd have to specify which cash flow you're talking about.
Um, it could be the payments on a bond or a mortgage or a loan.
We'll see. These are all like cash flows.
So a cash flow is something like, uh,
either a payment to or a payment from you,
uh, in various periods in time.
And here, by the way, the index is sometimes referred to as the period.
And it could be anything.
It could be days,
it could be quarters,
it could be years.
That- it doesn't matter,
depends on the application.
But that's a very common thing,
where x_i is a- a payment.
Um, so interesting question already.
Um, what does it mean if a cash flow vector is sparse?
That's- that's my question.
I mean, at the moment,
we don't have a whole lot of, uh,
concepts, but we have a couple and we might as well tie them together.
So that's my question to you,
is what does it mean if a- for a cash flow to be sparse?
Well, it means this,
it means that- let's say it's a cash flow vector.
Let's say it's 100 long.
So that means these are the payments made in 100 different periods.
Let's say it's months or something,
so it goes out about eight years or whatever it is, eight-and-a-half years.
Um, so that's a- that- that- that's a 100 long vector and it's been- it's sparse.
It means that in most months,
there is not a payment either by you or to you,
which is kind of interesting, right?
Um, so if it had like five non-zero entries, uh, If they're positive,
they could represent a- a payment that is to us,
and if it's negative, it could be a payment made by us.
And so that's what it would mean to be, uh,
to have a sparse cash flow vector.
Okay. Um, audio, so sound.
Um, so sound, uh,
is in fact, uh, what it is, is it's, uh,
it's- it's very fast variations in the press- air pressure, uh,
which your ear drum- uh,
which your ear picks up and your brain,
you know, allows you to perceive as sound.
Um, and so there are several ways to- to- uh,
to encode sound, but one is,
by the way, as a vector.
And typically what it is,
I mean, the most common format is this.
Um, it's a very long vector.
These are not short vectors, right?
These are long, long vectors.
But- uh, so basically what it is is it gives you
the sound pressure level at various instances of time,
and those instances of time are separated by very small amount of time,
around 25 microseconds, so it's about forty-four thousand, uh, per second.
I mean, there's other formats too,
it could be 48 kilohertz,
22 kilohertz, and- and this just means how many samples you have per second.
But nevertheless, that- that's what it looks like.
So that's what a- that- that- that's sound.
Sound is a vector, right?
And so, uh, for example,
an entry of a- an entry of
a sound vector would tell you what is the acoustic pressure at that particular moment.
By the way, the acoustic pressure, again, you don't need to know this,
but the acoustic pressure is
the actual pressure at that moment- at that exact moment in time,
minus kind of the average pressure,
uh, or minus the average pressure at that time.
And so it can be positive or negative.
That's- that's typically what it is.
So, um, okay.
So audio- audio track,
that's a, uh, that- that- that's a- that's a vector.
Um, here's an insanely- this is a super useful and common one,
is you can use a vector to describe, uh, so-called features.
Um, this is basically the entire core of machine learning,
uh, [NOISE] statistics, and many other fields.
But the basic idea is that a vector stores a bunch of numbers.
Um, each of them are either called features or
attributes of a- of a- of an entity, right?
So for example, I'll- I'll give you one.
Let's say that the entities correspond to a patient,
uh, being, uh, admitted to a hospital, right?
Um, the first entry, uh,
could be something like their weight,
uh, that would be x1.
X2 could be their height, um,
x3 could be their diastolic blood pressure,
and x4 could be their,
uh, you know, systolic blood pressure,
and so on and so forth.
Um, you- we can also do things like have some encoding.
So for example, we could encode- uh,
x5 could encode the sex of the patient,
and we could- we could assume we'd have- we'd have to have- we'd have to create a convention,
but we'd say something like x5 equals plus 1 if it's fema- if- if,
uh, the- if- if the patient is female,
minus 1 if male.
Right. So that would be,
uh, an- an example.
Um, but it can also have a lot more,
uh, a lot- a lot more things in it,
and feature vectors can be sometimes small with just 10 entries,
but they could be super big, right?
Um, so as an example,
we could do something like this.
Let's suppose that- let's talk about feature vectors for,
let's say, publicly traded companies, right?
So Google has a vector.
So- and here are the kinds of things you might find.
Here are the kind of attributes. It could be,
uh, let's say their- their total capitalization.
Um, the volatility.
That's how much the price of that thing has wiggled around over the last year.
It could be the last quarter's return.
Uh, it could be all sort- it could be the revenue,
it could be all sorts of things.
It could be the, the total number of dividends they paid in the last quarter.
So these are all attributes, uh, of- of companies.
And then we would have a lot of vectors and they would all- they would
all- each one would be associated with a company and so on,
um, and now you'd know what the entries meant.
Okay. Um, next example is, uh, customer purchase.
That's a super interesting, uh, vector right there.
So you're some kind of a store.
Well, let's say you're Amazon.
Um, then what you're gonna do is you're gonna
take a single customer and you're gonna ask over some period,
like the last year,
how much or what's the total dollar value of the- of what they bought.
Now, the length of that vector is actually gonna to
be- each entry in the vector is associated with the skew, right?
Which is a unique ID for a product that you can buy, right?
So, uh, so these vectors could be big.
These could be like a million long.
Uh, I once knew what the Amazon- uh,
what- what the number was for Amazon.
Actually, it was less than I thought it was, but it is not small.
Let's put it that way, okay? It's millions.
Um, but- but the idea there is then for a customer like me,
we could look up and figure out what have I bought in
the last year and it would be represented as a vector.
Now, by the way, that vector will for sure be super sparse, right?
Because of, let's say,
the one million things that I could order on Amazon.
Maybe it's 10 million, whatever.
Anyway, for whatever it is,
I may have ordered a couple of hundred things,
but I did not order- I didn't order anything close to all of them, right?
So- so that would be a natural example,
uh, in the wild of a sparse vector.
And in fact, it would be stored as a sparse vector, right?
It'd be a list of things that look like, you know,
the SKU and then the quantity,
you know, and that- that for us, it would be a vector.
That's a purch- that's a customer purchase vector.
Um, and that comes up very, very often.
Um, here's one, word count.
Um, that's a very interesting one, that we have a document.
We're gonna see a little bit- I'll say a little bit more about that in a bit.
Um, I have a document, and what we do is we simply count.
We also have a dictionary, and we count the number of times uh,
each word in my dictionary appears in that document, and that gives me x_i.
So x_i is literally [NOISE] the number of times word i appeared in the document, okay?
Could be zero. And by the way,
if it's sparse, it's interesting.
Sparsity there means that whatever your document is,
most of the words in your dictionary did not appear.
So that would be- that would make sense.
If your dictionary was like, you know,
an- a typical English dictionary,
you might have 50,000 entries.
Um, and suppose you're processing,
uh, reviews of products.
Well, they're- they're- they're a paragraph or so, right?
And I pre- pretty much guarantee you that most of the
80,000 or 50,000 words in English do not appear in each review.
[NOISE] So that's once again an example of a sparse vector, very sparse vector.
So, um, let's look into that in more detail and see how that works.
So [NOISE] here's a short document right here.
I mean, it doesn't say much, it's actually a snippet of text from the book.
Um, and so it- it's got a couple of sentences in it.
Uh, and, uh, here's our dictionary.
Our dictionary- and we have to agree on the dictionary, that's important.
You have to say what the dictionary is.
And the dictionary is- of course, would just be given by a list of words.
So our first word is, well, it's word,
our second word is in,
our third word is number, okay?
And then this, that is the word count [NOISE]
vector associated with this document using this dictionary, okay?
So let's audit at least one entry just to check.
Let's try, uh, the.
Okay. So here it is.
That's, uh, that's the.
Uh, let's go look up to the document and scan it and see how many times that came up.
Well, and I hope I'm- I hope this works out right.
So it's not in the first line.
Oh, oh, oh, oh. There's one, two, three, four, okay?
So four occur- occurrences.
[NOISE] And sure enough,
that's represented right here.
So that's that, okay?
So this is the, uh,
this is the idea, is that, uh,
fifth entry in the vector,
which tells you how many times the word the appeared in your document,
um, is fourth in this case, right?
Um, now, I should add this is just a baby example, right?
Uh, dictionaries typically have 1,000 entries,
um, oh, and they sometimes have a catch-all entry called- called Not in Dictionary.
So in other words, if you have some other weird word,
it just counts as a special word called Not in Dictionary,
but these are- that's a detail.
Uh, common dictionaries are thousands to,
and in some cases, even like a million, okay?
So dictionaries can get very,
uh, very, very large.
Um, and- but it's interesting, right?
Because you could imagine I could take
a Shakespeare play and I can write- I can get word count vectors,
probably 15, 20- maybe 15,000 different words appear
in it and it would be represented by a 15,000 vector, right?
Um, and that would be sort of the- the- the idea, very interesting.
So we're- we're gonna talk about all sorts of stuff you can do with
word count vectors, uh, later in the course.
But just- it's a good- that's one thing that a vector,
uh, that's one thing that a vector can represent.