Bdo Co1 Session 2

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 19

Department of CSE

COURSE NAME: BDO


COURSE CODE: 21CS3276R

TOPIC :
Representation of solution in R
Session - 2
AIM OF THE SESSION

The aim of a session on "Representation of solution in R" is to teach participants how to effectively communicate and
visualize solutions to problems using the R programming language.

INSTRUCTIONAL OBJECTIVES

This Session is designed to:


1. Demonstrate Representation of solution in R
2. Describe Evaluation Function
3. Describe the constraints.
4. List out the Optimization Methods

LEARNING OUTCOMES

At the end of this session, you should be able to:


1. Describe Representation of solution in R
2. Describe Evalution function.
3. describe the constarints.
4. list out the optimization methods.
Representation of solution in R

In R, a solution is typically represented using data structures, functions, and


packages, depending on the problem you are trying to solve. The representation of a
solution can vary widely depending on the context, so I'll provide a general overview
of how you might represent a solution in R and some common tools and techniques
used.
1. Data Structures:

 Vectors: Vectors are one-dimensional data structures that can hold elements of the same data type. You
can represent a solution as a vector of values. For example, if you are solving a linear programming
problem, the solution could be a vector of optimal variable values.

 Matrices and Data Frames: For more complex problems, you might use matrices or data frames to
represent solutions. For instance, if you are dealing with a dataset, the solution could be a data frame
with rows representing observations and columns representing variables.
2. Lists:

 Lists are versatile data structures in R that can hold elements of different data types. You can use lists
to represent complex solutions that consist of various components. For example, you might have a list
with components representing different aspects of your solution.

3. Functions:

 Functions are essential in R for solving problems. You can encapsulate a solution in a custom function.
This function can take inputs, perform computations, and return results. It's a way to modularize and
document your solution.
4. Packages:

 R has a rich ecosystem of packages that provide specialized functions and tools for solving specific
problems. You can use these packages to implement your solution efficiently. Some popular packages
include:

 dplyr and tidyr for data manipulation and tidying.

 ggplot2 for data visualization.

 optim for optimization problems.

 lm for linear regression.

 caret for machine learning and model training.

 lpSolve for linear programming.

 DEoptim for global optimization.


5. Objects:

 You can create custom objects to represent your solutions. These objects can
encapsulate the data and methods specific to your problem domain. For instance, if
you are working on a statistical analysis, you might create custom objects to hold the
results, such as regression model objects.

6. Data Analysis and Visualization:

 In some cases, your solution might involve data analysis and visualization. You can
use tools like the ggplot2 package to create visual representations of your results and
insights.
7. Report Generation:

 R Markdown is a powerful tool for generating reports that document your solutions. You
can combine R code, text, and visualizations in a single document to present your results
and methodology.
Here's a basic example of how you might represent a solution in R:

# Define a custom function to solve a problem

solve_problem <- function(input_data) {

# Perform computations

result <- input_data * 2

# Return the solution

return(result)

}
# Call the function with input data

input_data <- c(1, 2, 3, 4, 5)

solution <- solve_problem(input_data)

print(solution)
Evaluation Function

 Another important decision for handling optimization tasks is the definition of the
evaluation function, which should translate the desired goal (or goals) to be
maximized or minimized.

 Such function allows to compare different solutions, by providing either a rank or a


quality measure score.

 When considering numeric functions, the shape can be convex or non-convex, with
several local minima/maxima.
Constraints

 There are two main types of constraints:


hard and soft

 Hard constraints cannot be violated and are due to factors such as laws or
physical restrictions.

 Soft constraints are related with other (often non-priority) user goals, such
as increasing production efficiency while reducing environmental costs.
Optimization Methods

There are different dimensions that can be used to classify


optimization methods.

Three types of analysis adopted are:


1. The type of guided search
2. The search is deterministic or stochastic based;
3. and if the method is inspired by physical or biological
processes.
DEMONSTRATIVE PROBLEMS

1. sum of bits:

2. max sin:
REFERENCES FOR FURTHER LEARNING OF THE SESSION

Text Books :
:1. Paulo Cortez, “Modern Optimization with R “ Springer, (2014). 2. Nicholas J. Horton & Ken
Klein man, “ Using R and R Studio for Data Management, Statistical Analysis, and Graphics”,
SecondEdition , CRC Press, (2015).

Reference Books :
:1. Carlo Zaniolo, “Advanced database systems”, Morgan Kaufmann, Elsevier, (1997). 2.Jan L.
Harrington, “Relational Database Design”, Morgan Kaufmann, Elsevier, (2009).

Web Links :
:1. https://youtube.videoken.com/embed/ahXszIXr1NE?
rel=1&color1=0xcbba9f&color2=0xcbba9f&border=0&fs=1 2.
https://nptel.ac.in/courses/106/102/106102064/
TERMINAL QUESTIONS

1. Demonstrate Representation of solution in R


2. Describe Evaluation Function
3. Describe the constraints.
4. List out the Optimization Methods
THANK YOU

Team – DWDM

You might also like